jason-lang / jason

Jason is a fully-fledged interpreter for an extended version of AgentSpeak, a BDI agent-oriented logic programming language.
http://jason-lang.github.io
GNU Lesser General Public License v3.0
215 stars 67 forks source link

Jason does not (fully) support usage as a library #91

Closed gciatto closed 1 year ago

gciatto commented 3 years ago

I'd love to use Jason as a library in my Gradle-based projects. In particular I don't want to use Eclipse, nor Atom, nor sticking to any particular IDE. Plus, I'd like to avoid my projects to contain any .jar file.

I know that Jason .jars are available via the following Maven repository: http://jacamo.sourceforge.net/maven2/ So a simple solution coult be to setup my Jason project as follows (I use Kotlin as the build script language):

plugins {
    java
}

repositories {
    maven("http://jacamo.sourceforge.net/maven2")
    mavenCentral()
}

sourceSets {
    main {
        resources {
            srcDir("src/main/asl")
        }
    }
}

dependencies {
    implementation("org.jason-lang", "jason", "2.5-SNAPSHOT")
}

configure<JavaPluginConvention> {
    sourceCompatibility = JavaVersion.VERSION_1_8
}

Now suppose my project's structure is as follows:

.
├── build.gradle.kts
├── helloworld.mas2j
└── src
    └── main
        └── asl
            └── hello_agent.asl

I now may want to launch the system via a Gradle task, which I may set up as follows in build.gradle.kts:

task<JavaExec>("runHelloWorld") {
    group = "run"
    classpath = sourceSets.getByName("main").runtimeClasspath
    main = "jason.runtime.RunJasonProject"
    standardInput = System.`in`
    args(file("$projectDir/helloworld.mas2j").path)
}

Given the output of ./gradlew dependencies, I expect that dependencies ant and ant-launcher are in-classpath when launching Jason via the aforementioned task:

runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.jason-lang:jason:2.5-SNAPSHOT
     +--- org.apache.ant:ant:1.10.5
     |    \--- org.apache.ant:ant-launcher:1.10.5
     +--- net.sf.ingenias:jade:4.3
     +--- org.jacamo:cartago:2.3 -> 2.5
     \--- org.jacamo:jaca:2.3 -> 2.5

However, if I launch the task without having never configured Jason via the jason.util.ConfigGUI, I get the following message:

Ant is not properly configured! Current value is null
Problem defining the command to run the MAS!

before the program terminates. This is astonishing, as the ant-related .jars are in-classpath.

Now my point is that I don't want developers participating to my project to be constrained to manually configure Jason before they can run a self-configuring Gradle script. Plus, Jason's configuration is stored into a user.properties file hidden within the user's home directory. This breaks the self-containedness of my Gradle-projects.

I argue that it would be far better if jason.runtime.RunJasonProject could detect that ant is in-classpath and start the MAS even if no configuration has been previously performed---i.e. if the user.properties file is missing.

gciatto commented 3 years ago

One may work around this issue by configuring the task as follows:

task<JavaExec>("runHelloWorld") {
    group = "run"
    classpath = sourceSets.getByName("main").runtimeClasspath
    main = "jason.infra.centralised.RunCentralisedMAS"
    standardInput = System.`in`
    args(file("$projectDir/helloworld.mas2j").path)
}

i.e. by launching the RunCentralisedMAS class directly. However this is a workaround, and can only work with centralised MAS.

jomifred commented 3 years ago

Hi @gciatto-unibo ,

what you are trying to do should work, otherwise, it is a bug and should be fixed.

We tried to remove the dependency of local configuration files recently.... I am not sure if it is available in Jason 2.5. Do you mind to try Jason 2.6.2? (it is available in the GitHub repository @cleberjamaral has mentioned in the other thread)

Note also that the dependency groups has changed:

    implementation("org.jason", "jason", "2.6.2")
gciatto commented 3 years ago

I confirm: the issue is still there with version 2.6.2

jomifred commented 3 years ago

I didn’t realised you are using jason.runtime.RunJasonProject….

I repeated the issue here and will see how to fix it.

On 13 Apr 2021, at 12:03, Giovanni Ciatto @.***> wrote:

I confirm: the issue is still there with version 2.6.2

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

jomifred commented 3 years ago

I hope I have fixed it. Could you try with Jason-2.6.3-SNAPSHOT? (available in the GitHub repo)

jomifred commented 3 years ago

It makes sense to use RunCentralisedMAS in gradle.

RunJasonProject is used to create a script to execute the project (and then run it). Ant is used for this script. Once gradle is used in place of Ant, no need to write scripts.

RunCentralisedMas is not a good name for the class, it will be renamed to RunLocalMAS in the future. Since it runs some agentes (from .mas2j) in the a local machine (a JVM indeed). These local agents may belong to a distributed system.

On 13 Apr 2021, at 11:40, Giovanni Ciatto @.***> wrote:

One may work around this issue by configuring the task as follows:

task("runHelloWorld" ) { group = "run"

classpath 

= sourceSets.getByName("main" ).runtimeClasspath main = "jason.infra.centralised.RunCentralisedMAS"

standardInput 

= System.in args(file( "$projectDir/helloworld.mas2j" ).path) }

i.e. by launching the RunCentralisedMAS class directly. However this is a workaround, and can only work with centralised MAS.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.