diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..7d0f12d --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,27 @@ +name: build + +# https://docs.github.com/en/free-pro-team@latest/actions/managing-workflow-runs/adding-a-workflow-status-badge + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build and test with Gradle + # https://stackoverflow.com/questions/50104666/gradle-difference-between-test-and-check + # https://stackoverflow.com/questions/50104666/gradle-difference-between-test-and-check + run: ./gradlew clean check --stacktrace --info \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..311d9bc --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,41 @@ +# Created with https://github.com/marketplace/actions/create-a-release + +on: + push: + # Sequence of patterns matched against refs/tags +# branches: +# - master + tags: + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 + +name: Create Release + + +jobs: + build: + name: Create Release + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + # https://github.community/t/accessing-commit-message-in-pull-request-event/17158/8 +# - name: get commit message +# run: | +# echo ::set-env name=commitmsg::$(git log --format=%B -n 1 ${{ github.event.after }}) +# - name: show commit message +# run: echo $commitmsg + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + with: + # https://stackoverflow.com/questions/63619329/github-action-get-commit-message +# tag_name: ${{ github.event.head_commit.message }} +# release_name: ${{ github.event.head_commit.message }} + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + body: | + See [CHANGES.md](https://github.com/holgerbrandl/krangl/blob/master/CHANGES.md) for new features, bug-fixes and changes. + draft: false + prerelease: false \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1b42a08..03aa93f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,80 +1,13 @@ -# Created by .ignore support plugin (hsz.mobi) -### Java template - -*.class - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.ear - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - - -### Gradle template +#gradle .gradle -build/ - -# Ignore Gradle GUI config -gradle-app.setting - -# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) -!gradle-wrapper.jar - -# Cache of project -.gradletasknamecache - -# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 -# gradle/wrapper/gradle-wrapper.properties - - -### JetBrains template -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff: -.idea/workspace.xml -.idea/tasks.xml -.idea/dictionaries -.idea/vcs.xml -.idea/jsLibraryMappings.xml - -# Sensitive or high-churn files: -.idea/dataSources.ids -.idea/dataSources.xml -.idea/dataSources.local.xml -.idea/sqlDataSources.xml -.idea/dynamic.xml -.idea/uiDesigner.xml - -# Gradle: -.idea/gradle.xml -.idea/libraries - -# Mongo Explorer plugin: -.idea/mongoSettings.xml - -## File-based project format: -*.iws - -## Plugin-specific files: +/build/ # IntelliJ -/out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml +out/ +.idea +*iml -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties +# sonatype credentials +local.properties +*.gpg \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0f5fd25..0000000 --- a/.travis.yml +++ /dev/null @@ -1,10 +0,0 @@ -language: java -jdk: - - oraclejdk8 - -## https://docs.travis-ci.com/user/languages/java -## http://stackoverflow.com/questions/20707017/how-to-run-junit-tests-with-gradle -## how to run tests with gradle https://docs.gradle.org/current/userguide/tutorial_gradle_command_line.html -## gradle check or gradle test - -## http://stackoverflow.com/questions/17606874/trigger-a-travis-ci-rebuild-without-pushing-a-commit \ No newline at end of file diff --git a/README.md b/README.md index eb8a80c..dbbbe6f 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,7 @@ Support API for `kscript` ========================= -[![Build Status](https://travis-ci.org/holgerbrandl/kscript-support-api.svg?branch=master)](https://travis-ci.org/holgerbrandl/kscript-support-api) [ ![Download](https://api.bintray.com/packages/holgerbrandl/github/kscript/images/download.svg) ](https://bintray.com/holgerbrandl/github/kscript/_latestVersion)[](https://bintray.com/) - +[ ![Download](https://img.shields.io/badge/Maven%20Central-1.2.5-orange) ](https://mvnrepository.com/artifact/com.github.holgerbrandl/kscript-support-api) [![Build Status](https://github.com/holgerbrandl/krangl/workflows/build/badge.svg)](https://github.com/holgerbrandl/kscript-support-api/actions?query=workflow%3Abuild) @@ -27,7 +26,7 @@ Even if the artifact is intended to be used alongside with `kscript` you can als To get started simply add it as a dependency via Jcenter: ``` -compile "com.github.holgerbrandl:kscript:1.2.1" +compile "com.github.holgerbrandl:kscript-support-api:1.2.5" ``` diff --git a/build.gradle b/build.gradle index 286210d..9766c14 100644 --- a/build.gradle +++ b/build.gradle @@ -1,128 +1,100 @@ +//file:noinspection DifferentKotlinGradleVersion buildscript { - ext.kotlin_version = '1.1.2' + ext.kotlin_version = '1.4.32' + repositories { mavenCentral() } + dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } -plugins { id "com.jfrog.bintray" version "1.2" } +plugins { + id "java-library" +// id "application" + id "maven-publish" + id "signing" + id "io.github.gradle-nexus.publish-plugin" version "1.1.0" + id "org.jetbrains.kotlin.jvm" version "1.4.32" +} -apply plugin: 'kotlin' -apply plugin: 'application' -apply plugin: 'maven' -apply plugin: 'maven-publish' - -//mainClassName = 'demo.HelloWorldKt' -mainClassName = "de.mpicbg.scicomp.kutils.BashKt" // not needed but does not work without defaultTasks 'run' repositories { mavenCentral() - mavenLocal() +// mavenLocal() } // https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_plugin_and_dependency_management dependencies { -// compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" +// compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "com.offbytwo:docopt:0.6.0.20150202" testCompile 'junit:junit:4.11' testCompile "io.kotlintest:kotlintest:2.0.1" } -// http://stackoverflow.com/questions/11474729/how-to-build-sources-jar-with-gradle -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource +java { + withJavadocJar() + withSourcesJar() } -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -//http://stackoverflow.com/questions/34377367/why-is-gradle-install-replacing-my-version-with-unspecified -//group = 'de.mpicbg.scicomp' group = 'com.github.holgerbrandl' -//version = '1.1.9' -version = '1.2.3' +version = '1.2.5' -artifacts { - archives sourcesJar - archives javadocJar -} - publishing { publications { - maven(MavenPublication) { - from components.java - artifact sourcesJar { classifier "sources" } - - // just needed because artifact name differs from projet name - version = project.version - artifactId = 'kscript' - groupId = project.group + mavenJava(MavenPublication) { + from(components.java) + + pom { + name = "kscript-support-api" + description = 'A support API to simplify scripting with kscript' + url = 'https://github.com/holgerbrandl/kscript-support-api' + + licenses { + license { + name = 'MIT' + url = 'https://github.com/holgerbrandl/kscript-support-api/blob/master/LICENSE' + } + } + + + scm { + connection = 'scm:git:github.com/holgerbrandl/kscript-support-api.git' + url = 'https://github.com/holgerbrandl/kscript-support-api.git' + } + + + developers { + developer { + id = 'holgerbrandl' + name = 'Holger Brandl' + email = 'holgerbrandl@gmail.com' + } + } + } } } } -// https://docs.gradle.org/current/userguide/maven_plugin.html -uploadArchives { - repositories { - mavenDeployer { -// pom.groupId = 'de.mpicbg.scicomp' -// pom.version = '0.1-SNAPSHOT' - pom.artifactId = 'kscript' - repository(url: "file://localhost/tmp/myRepo/") +nexusPublishing { + repositories { + sonatype { + snapshotRepositoryUrl = uri(project.properties["sonatypeStagingProfileId"]) + username = project.properties["ossrhUsername"] + password = project.properties["ossrhPassword"] } } } - -install { - repositories.mavenInstaller { - pom.version = project.version - pom.artifactId = 'kscript' - pom.groupId = project.group - } -} - -if (hasProperty('bintray_user') && hasProperty('bintray_key')) { - bintray { - - // property must be set in ~/.gradle/gradle.properties - user = bintray_user - key = bintray_key - - publications = ['maven'] //When uploading configuration files - - dryRun = false //Whether to run this as dry-run, without deploying - publish = true // If version should be auto published after an upload - - pkg { - repo = 'github' - name = 'kscript' - vcsUrl = 'https://github.com/holgerbrandl/kscript-support-api' - - licenses = ['MIT'] - publicDownloadNumbers = true - - //Optional version descriptor - version { - name = project.version //Bintray logical version name - desc = '.' - released = new java.util.Date() - vcsTag = 'v' + project.version - } - } - /**/ - } -} +signing { + sign publishing.publications.mavenJava +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..91ca28c Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..3c9d085 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..cccdd3d --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..f955316 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/kotlin/kscript/text/StreamUtil.kt b/src/main/kotlin/kscript/text/StreamUtil.kt index 57417fc..f1af2cb 100644 --- a/src/main/kotlin/kscript/text/StreamUtil.kt +++ b/src/main/kotlin/kscript/text/StreamUtil.kt @@ -49,6 +49,9 @@ fun Sequence.print() = forEach { println(it) } fun Iterable.print() = forEach { println(it) } +fun Iterable.trim() = map { it.trim() } +fun Sequence.trim() = map { it.trim() } + //https://dzone.com/articles/readingwriting-compressed-and /** Save a list of items into a file. Output can be option ally zipped and a the stringifying operation can be changed from toString to custom operation if needed. */ diff --git a/suport_api_notes.md b/suport_api_notes.md index 25e77c0..766c335 100644 --- a/suport_api_notes.md +++ b/suport_api_notes.md @@ -22,25 +22,32 @@ Release Checklist * `kscript/README` -1. Push and create github release tag - -2. +2. Do the central release ```bash -# cd /Users/brandl/projects/kotlin/kscript-support-api +# cd /c/brandl_data/projects/misc/kscript-support-api + +./gradlew install -gradle test -gradle install +./gradlew publishToMavenLocal + +#./gradlew publishToSonatype closeSonatypeStagingRepository +./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository ``` -4. Create new version on jcenter +3. Do the github source release -* Upload jar, sources.jar and pom for new version from `~/.m2/repository/com/github/holgerbrandl/kscript` to: -> https://bintray.com/holgerbrandl/mpicbg-scicomp/kscript +```bash + +# make sure that are no pending chanes +#(git diff --exit-code && git tag v${kscript_version}) || echo "could not tag current branch" +git diff --exit-code || echo "There are uncommitted changes" -1. Check for release status on -https://jcenter.bintray.com/com/github/holgerbrandl/kscript -2. Bump versions for new release cycle +git tag "1.2.5" + +git push origin +git push origin --tags +``` Links