Skip to content

Commit

Permalink
Add script runner
Browse files Browse the repository at this point in the history
  • Loading branch information
sagebind committed Apr 28, 2017
1 parent 46ab4c7 commit c9aba61
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
/.idea/workspace.xml
/.idea/libraries
/.idea/shelf
/build
build
*.class
.DS_Store
53 changes: 34 additions & 19 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'signing'

group 'com.widen.oss'
archivesBaseName = 'tabitha'
version '0.1.0-alpha1'
archivesBaseName = 'tabitha'

sourceCompatibility = 1.8
targetCompatibility = 1.8
allprojects {
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'maven'

ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
ext.username = hasProperty("ossrhUsername") ? ossrhUsername : System.getenv("OSSRH_USERNAME")
ext.password = hasProperty("ossrhPassword") ? ossrhPassword : System.getenv("OSSRH_PASSWORD")
group 'com.widen.oss'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()
}

repositories {
mavenCentral()
sourceSets {
main {
java {
srcDirs = ['src/main/java']
}
resources {
srcDirs = ['src/main/resources']
}
}
test {
groovy {
srcDirs = ['src/test/groovy']
}
}
}
}

ext.isReleaseVersion = !version.endsWith('SNAPSHOT')
ext.username = hasProperty('ossrhUsername') ? ossrhUsername : System.getenv('OSSRH_USERNAME')
ext.password = hasProperty('ossrhPassword') ? ossrhPassword : System.getenv('OSSRH_PASSWORD')

dependencies {
compile 'com.opencsv:opencsv:3.8'
compile 'commons-collections:commons-collections:3.2.1'
Expand All @@ -32,7 +51,6 @@ dependencies {
testCompile 'cglib:cglib-nodep:3.2.5'
}


task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
Expand All @@ -52,7 +70,7 @@ artifacts {
signing {
sign configurations.archives
required {
isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives")
isReleaseVersion && gradle.taskGraph.hasTask('uploadArchives')
}
}

Expand All @@ -61,11 +79,11 @@ uploadArchives {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/') {
authentication(userName: username, password: password)
}

snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/') {
authentication(userName: username, password: password)
}

Expand All @@ -74,21 +92,18 @@ uploadArchives {
packaging 'jar'
description 'Tabular data reading, writing, and processing library'
url 'https://github.com/Widen/tabitha'

scm {
url 'https://github.com/Widen/tabitha'
connection 'scm:git@github.com:Widen/tabitha.git'
developerConnection 'scm:git@github.com:Widen/tabitha.git'
}

licenses {
license {
name 'The MIT License'
url 'https://opensource.org/licenses/MIT'
distribution 'repo'
}
}

developers {
developer {
id 'scoakley'
Expand Down
10 changes: 10 additions & 0 deletions runner/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apply plugin: 'application'

version '1.0.0'
mainClassName = 'com.widen.tabitha.runner.Runner'

dependencies {
compile project(':')
compile 'commons-io:commons-io:2.5'
compile 'org.codehaus.groovy:groovy-all:2.4.1'
}
55 changes: 55 additions & 0 deletions runner/src/main/java/com/widen/tabitha/runner/Runner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.widen.tabitha.runner;

import groovy.lang.GroovyShell;
import org.apache.commons.io.IOUtils;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.customizers.ImportCustomizer;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

public class Runner
{
private static File scriptFile;

public static void main(String[] args) throws IOException
{
for (String arg : args)
{
if (arg.equals("-h") || arg.equals("--help") || arg.equals("-?") || arg.equals("/?"))
{
printHelp();
return;
}
else
{
scriptFile = new File(arg);
break;
}
}

execute();
}

private static void printHelp() throws IOException
{
InputStream inputStream = Runner.class.getClassLoader().getResourceAsStream("Help.txt");
String text = IOUtils.toString(inputStream, "UTF-8");
System.out.println(text);
}

private static void execute() throws IOException
{
ImportCustomizer importCustomizer = new ImportCustomizer();
importCustomizer.addStarImports("com.widen.tabitha");
importCustomizer.addStarImports("com.widen.tabitha.formats");
importCustomizer.addStarImports("com.widen.tabitha.parallel");

CompilerConfiguration configuration = new CompilerConfiguration();
configuration.addCompilationCustomizers(importCustomizer);

GroovyShell shell = new GroovyShell(configuration);
shell.evaluate(scriptFile);
}
}
9 changes: 9 additions & 0 deletions runner/src/main/resources/Help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Tabitha Runner

Usage:
tabitha-runner [options] <script>

Run a given Groovy script with Tabitha classes already available.

Options:
-h, --help Show this help message.
4 changes: 4 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include 'runner'

rootProject.name = 'tabitha'
project(':runner').name = 'tabitha-runner'

0 comments on commit c9aba61

Please sign in to comment.