Skip to content

Commit

Permalink
publish jason cli as a jar (for jacamo)
Browse files Browse the repository at this point in the history
  • Loading branch information
jomifred committed Dec 20, 2024
1 parent db3e20d commit e53abe4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ clean {
}

task createCLIBin (dependsOn: [':jason-cli:createBin']) {
group "build"
doLast {
copy {
from 'jason-cli/build/bin/jason'
Expand Down
50 changes: 48 additions & 2 deletions jason-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
defaultTasks 'build'

apply plugin: 'java-library'
apply plugin: 'maven-publish'

version "${jasonVersion}"
group "${groupId}"

sourceSets {
main {
Expand Down Expand Up @@ -39,7 +42,7 @@ dependencies {
}

jar {
archiveBaseName = "jason-cli-${jasonVersion}"
archiveBaseName = "jason-cli"
manifest {
attributes 'Main-Class': 'jason.cli.JasonCLI',
'Specification-Title': 'Jason CLI',
Expand Down Expand Up @@ -80,6 +83,7 @@ task run (type: JavaExec, dependsOn: 'build') {
}

task uberJar(type: Jar, dependsOn: ['classes', ':jason-interpreter:jar']) {
group "build"
description 'creates a single runnable jar file with all dependencies'
duplicatesStrategy 'exclude'

Expand All @@ -89,13 +93,14 @@ task uberJar(type: Jar, dependsOn: ['classes', ':jason-interpreter:jar']) {
'Specification-Version': "${jasonVersion}",
'Implementation-Version': new Date().toString()
}
archiveBaseName = "jason-cli-all-${jasonVersion}"
archiveBaseName = "jason-cli-all"
destinationDirectory = file('build/bin')
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}

task createBin (dependsOn: ['uberJar']) {
group "build"
def wdir = 'build/bin'
doFirst {
exec {
Expand All @@ -117,6 +122,47 @@ task createBin (dependsOn: ['uberJar']) {
}
}

artifacts {
archives jar
}

publishing {
publications {
maven(MavenPublication) {
from components.java
artifactId 'jason-cli'
}
}
}

task publishMavenGitHub(dependsOn: [ 'build', 'publishToMavenLocal']) {
group = "publishing"
doLast {
def wdir = System.getProperty("user.home")+'/.m2/repository/io/github/jason-lang/jason-cli'
def rdir = project.projectDir.absolutePath+'/../../jacamo-mvn-repo'
exec {
commandLine 'git', 'pull'
workingDir rdir
}
copy {
from wdir
into rdir + '/io/github/jason-lang/jason-cli'
}
exec {
commandLine 'git', 'add', '*'
workingDir rdir
}
exec {
commandLine 'git', 'commit', '-a', '-m', 'new version of jason-cli '+project.version
workingDir rdir
}
exec {
commandLine 'git', 'push'
workingDir rdir
}
}
}

//task release (type: Zip, dependsOn: 'createBin') {
// def wdir = 'build/jason-' + "${jasonVersion}"
// from wdir
Expand Down
19 changes: 18 additions & 1 deletion jason-cli/src/main/java/jason/cli/JasonCLI.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package jason.cli;

import jason.cli.agent.Agent;
import jason.cli.app.Application;
import jason.cli.app.Run;
import jason.cli.mas.MAS;
import jason.cli.mas.RunningMASs;
import jason.util.Config;
import org.fusesource.jansi.AnsiConsole;
Expand All @@ -24,6 +27,7 @@
import java.util.function.Supplier;

// program "inspired" by https://github.com/remkop/picocli/tree/v4.7.1/picocli-shell-jline3
// see https://picocli.info/#_sharing_options_in_subcommands

public class JasonCLI {

Expand All @@ -44,12 +48,23 @@ public static void main(String[] args) {
// case of .mas2j
new Run().run(args[0], args.length == 2 && args[1].equals("-v"));
} else {
int exitCode = new CommandLine(new JasonCommands()).execute(args);
var cmd = new CommandLine(new JasonCommands());
addSubCmd(cmd);
int exitCode = cmd.execute(args);

if (!RunningMASs.hasLocalRunningMAS())
System.exit(exitCode);
}
}

static void addSubCmd(CommandLine cmd) {
cmd.addSubcommand("app", new Application());
cmd.addSubcommand("mas", new MAS());
cmd.addSubcommand("agent", new Agent());
cmd.addSubcommand("echo", new Echo());
cmd.addSubcommand("wait", new Wait());
}

static void startTerminal() {
AnsiConsole.systemInstall();
try {
Expand All @@ -68,6 +83,8 @@ static void startTerminal() {
// PicocliCommandsFactory factory = new PicocliCommandsFactory(customFactory); // chain the factories

CommandLine cmd = new CommandLine(jasonCommands, factory);
addSubCmd(cmd);

PicocliCommands picocliCommands = new PicocliCommands(cmd);

var parser = new DefaultParser();
Expand Down
4 changes: 2 additions & 2 deletions jason-cli/src/main/java/jason/cli/JasonCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
import java.io.PrintWriter;

// program "inspired" by https://github.com/remkop/picocli/tree/v4.7.1/picocli-shell-jline3
// see https://picocli.info/#_sharing_options_in_subcommands

@Command(name = "jason",
// version = "1.0",
versionProvider = jason.cli.VersionProvider.class,
mixinStandardHelpOptions = true,
subcommands = { Application.class, MAS.class, Agent.class, Echo.class, Wait.class },
//subcommands = { Application.class, MAS.class, Agent.class, Echo.class, Wait.class },
synopsisSubcommandLabel = "(app | mas | agent | <mas2j file>)"
)
public class JasonCommands {

private PrintWriter out = null;
private PrintWriter err = null;

public PrintWriter getOut() {
return out;
Expand Down

0 comments on commit e53abe4

Please sign in to comment.