Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault committed May 29, 2020
0 parents commit 0e38181
Show file tree
Hide file tree
Showing 13 changed files with 554 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: CI
on:
push:
branches:
- master
tags:
- "v*"
pull_request:

jobs:
test:
runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v1

- name: coursier cache
uses: actions/cache@v1
if: runner.OS == 'Linux'
with:
path: ~/.cache/coursier
key: ${{ runner.OS }}-coursier-cache-${{ hashFiles('**/*.sbt') }} # -${{ hashFiles('project/**.scala') }} (fails for now)
restore-keys: |
${{ runner.OS }}-coursier-cache-${{ hashFiles('**/*.sbt') }}-
${{ runner.OS }}-coursier-cache-
- uses: olafurpg/setup-scala@v7
with:
java-version: [email protected]

- name: Compile
run: csbt test

publish:
needs: test
if: github.event_name == 'push'
runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v1

- name: coursier cache (Linux)
uses: actions/cache@v1
if: runner.OS == 'Linux'
with:
path: ~/.cache/coursier
key: ${{ runner.OS }}-coursier-cache-${{ hashFiles('**/*.sbt') }} # -${{ hashFiles('project/**.scala') }} (fails for now)
restore-keys: |
${{ runner.OS }}-coursier-cache-${{ hashFiles('**/*.sbt') }}-
${{ runner.OS }}-coursier-cache-
- uses: olafurpg/setup-scala@v7

- uses: olafurpg/setup-gpg@v2

- name: Release
run: csbt ci-release
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
26 changes: 26 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

inThisBuild(List(
organization := "io.get-coursier.sbt",
homepage := Some(url("https://github.com/coursier/sbt-runner")),
licenses := Seq("Apache 2.0" -> url("http://opensource.org/licenses/Apache-2.0")),
developers := List(
Developer(
"alexarchambault",
"Alexandre Archambault",
"",
url("https://github.com/alexarchambault")
)
)
))

// publishing
sonatypeProfileName := "io.get-coursier"

// pure Java
crossPaths := false
autoScalaLibrary := false

name := "sbt-runner"

resolvers += Resolver.jcenterRepo
libraryDependencies += "net.aichler" % "jupiter-interface" % JupiterKeys.jupiterVersion.value % Test
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.3.10
4 changes: 4 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.3")
addSbtPlugin("net.aichler" % "sbt-jupiter-interface" % "0.8.3")

resolvers += Resolver.jcenterRepo // for sbt-jupiter-interface
62 changes: 62 additions & 0 deletions src/main/java/sbtrunner/SbtRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package sbtrunner;

import sbtrunner.args.HelpAskedException;
import sbtrunner.args.ParsedArgs;
import sbtrunner.args.ParsingArgumentsException;

import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;

public class SbtRunner {

public static void main(String[] args) {
Iterator<String> it = Arrays.asList(args).iterator();
ParsedArgs parsedArgs = null;
try {
parsedArgs = ParsedArgs.process(it);
} catch (HelpAskedException ex) {
try {
HelpAskedException.printHelp();
System.exit(0);
} catch (IOException ex0) {
throw new RuntimeException(ex0);
}
} catch (ParsingArgumentsException | IOException ex) {
throw new RuntimeException(ex);
}

parsedArgs.setSystemProperties();

Class<?> cls;
try {
cls = Class.forName("xsbt.boot.Boot");
} catch (ClassNotFoundException ex) {
throw new RuntimeException(ex);
}

Method main;
try {
main = cls.getMethod("main", String[].class);
} catch (NoSuchMethodException ex) {
throw new RuntimeException(ex);
}

String[] sbtArgs = parsedArgs.getArgs();

try {
main.invoke(null, (Object) sbtArgs);
} catch (InvocationTargetException ex) {
Throwable cause = ex.getCause();
if (cause == null) {
System.err.println("Something went wrong: " + ex);
ex.printStackTrace(System.err);
} else
throw new RuntimeException(cause);
} catch (IllegalAccessException ex) {
System.err.println("Something went wrong: " + ex);
ex.printStackTrace(System.err);
}
}
}
35 changes: 35 additions & 0 deletions src/main/java/sbtrunner/args/HelpAskedException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package sbtrunner.args;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

public class HelpAskedException extends ParsingArgumentsException {

static final String helpResourcePath = "sbtrunner/help.txt";

public static void printHelp() throws IOException {
try (InputStream is = Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream(helpResourcePath)) {
if (is == null) {
System.err.println("[" + helpResourcePath + " resource not found]");
return;
}

BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));

String line;
while ((line = reader.readLine()) != null) {
if (!line.startsWith("#"))
System.out.println(line);
}
}
}

public HelpAskedException() {
super(null, 0);
}
}
20 changes: 20 additions & 0 deletions src/main/java/sbtrunner/args/MissingArgumentException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package sbtrunner.args;

public class MissingArgumentException extends ParsingArgumentsException {

private final String type;
private final String opt;

public MissingArgumentException(String type, String opt) {
super(opt + " requires <" + type + "> argument", 1);
this.type = type;
this.opt = opt;
}

public String getType() {
return type;
}
public String getOpt() {
return opt;
}
}
Loading

0 comments on commit 0e38181

Please sign in to comment.