diff --git a/jason-cli/src/main/java/jason/cli/agent/RunAsAgent.java b/jason-cli/src/main/java/jason/cli/agent/RunAsAgent.java index 569245c9..f408791b 100644 --- a/jason-cli/src/main/java/jason/cli/agent/RunAsAgent.java +++ b/jason-cli/src/main/java/jason/cli/agent/RunAsAgent.java @@ -1,18 +1,10 @@ package jason.cli.agent; -import jason.architecture.AgArch; -import jason.asSemantics.IntendedMeans; -import jason.asSemantics.Intention; -import jason.asSemantics.Option; -import jason.asSemantics.Unifier; -import jason.asSyntax.ASSyntax; -import jason.asSyntax.Plan; -import jason.asSyntax.PlanBody; import jason.cli.mas.RunningMASs; -import jason.stdlib.print_unifier; import picocli.CommandLine; import picocli.CommandLine.Command; +import java.rmi.RemoteException; import java.util.List; @@ -20,13 +12,16 @@ name = "run-as", description = "executes commands for an agent" ) -public class RunAsAgent implements Runnable { +public class RunAsAgent extends BaseAgent implements Runnable { @CommandLine.Parameters(paramLabel = "", defaultValue = "", arity = "1", description = "agent unique identification") String agName; + @CommandLine.Option(names = { "--mas-name" }, paramLabel = "", defaultValue = "", description = "MAS identification where to find the agent") + String masName; + @CommandLine.Parameters(hidden = true) // "hidden": don't show this parameter in usage help message List allParameters; // no "index" attribute: captures _all_ arguments @@ -35,35 +30,45 @@ public class RunAsAgent implements Runnable { @Override public void run() { - if (!RunningMASs.hasLocalRunningMAS()) { - parent.parent.errorMsg("no local running MAS, so, no agent to run the commands."); - return; - } + masName = testMasName(masName, parent.parent); + testRunningMAS(masName, parent.parent); + if (agName.isEmpty()) { parent.parent.errorMsg("the name of the agent should be informed, e.g., 'agent run-as bob { .print(oi) }'."); return; } - if (!RunningMASs.hasAgent(null, agName)) { + + if (!RunningMASs.hasAgent(masName, agName)) { parent.parent.errorMsg("the agent with name " + agName + " is not running!"); return; } String code = ""; - if (allParameters.size()>0) { + if (!allParameters.isEmpty()) { var last = allParameters.get( allParameters.size()-1).trim(); + if (last.startsWith("{")) { code = last.substring(1,last.length()-1).trim(); } + if (last.startsWith("}")) { + code = allParameters.get( allParameters.size()-2).trim(); + } } if (!code.isEmpty()) { - execCmd(code, RunningMASs.getLocalRunningMAS().getAg(agName)); + try { + var r = RunningMASs.getRTS(masName).runAsAgent(agName, code); + parent.parent.println(r); + } catch (RemoteException e) { + parent.parent.errorMsg("Error executing "+code+"\n"+e); + e.printStackTrace(); + } } else { parent.parent.errorMsg("no code to execute was informed. E.g., 'agent run-as bob { .print(oi) }' "); } } - void execCmd(String sCmd, AgArch ag) { + /*void execCmd(String sCmd, AgArch ag) { try { sCmd = sCmd.trim(); if (sCmd.endsWith(".")) @@ -97,7 +102,7 @@ void execCmd(String sCmd, AgArch ag) { } catch (Exception e) { parent.parent.errorMsg("Error parsing "+sCmd+"\n"+e); } - } + }*/ } diff --git a/jason-interpreter/build.gradle b/jason-interpreter/build.gradle index 2b4c9adb..93c0b24a 100644 --- a/jason-interpreter/build.gradle +++ b/jason-interpreter/build.gradle @@ -98,6 +98,7 @@ publishing { task publishMavenGitHub(dependsOn: [ 'build', 'publishToMavenLocal']) { + group = "publishing" doLast { def wdir = System.getProperty("user.home")+'/.m2/repository/io/github/jason-lang/jason-interpreter' //org/jason/jason' def rdir = project.projectDir.absolutePath+'/../../jacamo-mvn-repo' diff --git a/jason-interpreter/src/main/java/jason/infra/local/LocalRuntimeServices.java b/jason-interpreter/src/main/java/jason/infra/local/LocalRuntimeServices.java index a2e57fd3..84d5e171 100644 --- a/jason-interpreter/src/main/java/jason/infra/local/LocalRuntimeServices.java +++ b/jason-interpreter/src/main/java/jason/infra/local/LocalRuntimeServices.java @@ -237,7 +237,7 @@ public String runAsAgent(String agName, String code) { } catch (Exception e) { return "Error parsing "+code+"\n"+e; } - return "ok"; + return "execution ok"; } } diff --git a/jason-interpreter/src/main/java/jason/runtime/RuntimeServices.java b/jason-interpreter/src/main/java/jason/runtime/RuntimeServices.java index 5d09b0e1..4edfef13 100644 --- a/jason-interpreter/src/main/java/jason/runtime/RuntimeServices.java +++ b/jason-interpreter/src/main/java/jason/runtime/RuntimeServices.java @@ -82,7 +82,7 @@ default public void clone(Agent source, List archClasses, String agName) default public String loadASL(String agName, String code, String sourceId, boolean replace) throws RemoteException { return "not implemented"; } /** agent agName executes the code (in a new intention) */ - //public String runAsAgent(String agName, String code); + default public String runAsAgent(String agName, String code) throws RemoteException { return "not implemented"; } /** Stops all MAS (the agents, the environment, the controller, ...) */ public void stopMAS(int deadline, boolean stopJVM, int exitValue) throws RemoteException, Exception;