Skip to content

Commit

Permalink
execute .mas2j without .jason configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jomifred committed Oct 31, 2016
1 parent 402f7ac commit c63140a
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 25 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Expand Up @@ -45,8 +45,8 @@ configurations {
dependencies {
compile group: 'net.sf.ingenias', name: 'jade', version: '4.3'
//compile group: 'com.tilab.jade', name: 'jade', version: '4.4.0'
compile group: 'org.jacamo', name: 'cartago', version: '2.2'
compile group: 'org.jacamo', name: 'jaca', version: '2.2'
compile group: 'org.jacamo', name: 'cartago', version: '2.3-SNAPSHOT'
compile group: 'org.jacamo', name: 'jaca', version: '2.3-SNAPSHOT'

// from jEdit
compile fileTree(dir: 'jedit', include: '*.jar') // using fileTree, jedit jars are not included as a dependency in the pom file
Expand Down Expand Up @@ -203,7 +203,7 @@ eclipse {
}
file.whenMerged { cp ->
logger.lifecycle "Removing duplicate classpath entries from eclipse for project '${project.name}'"

Map entryByPath = cp.entries.groupBy { entry -> entry.path }
entryByPath.each { key, values ->
if (values.size() > 1) {
Expand Down
5 changes: 2 additions & 3 deletions doc/tutorials/hello-bdi/readme.adoc
Expand Up @@ -106,9 +106,8 @@ in this case).
=== Execution

* Create a new project (you can use either
http://jason.sourceforge.net/mini-tutorial/getting-started/[jEdit] or
http://jason.sourceforge.net/mini-tutorial/eclipse-plugin/[Eclipse]
Jason plugins, or the http://jacamo.sourceforge.net/eclipseplugin/tutorial/[JaCaMo plugin]).
http://jason.sourceforge.net/mini-tutorial/getting-started/[Jason jEdit],
http://jason.sourceforge.net/mini-tutorial/eclipse-plugin/[Jason Eclipse], http://jacamo.sourceforge.net/eclipseplugin/tutorial/[JaCaMo Eclipse], or http://jacamo.sourceforge.net/tutorial/hello-world/shell-based.html[JaCaMo shell based commands]).
* Create agent Bob with the source code above. The project should
look like:
+
Expand Down
11 changes: 9 additions & 2 deletions scripts/jason-setup
Expand Up @@ -2,16 +2,16 @@

JasonREL=2.1


if [ -z $JASON_HOME ] ; then
CURDIR=`pwd`
JASON_HOME=`dirname $0`
cd "$JASON_HOME/.."
JASON_HOME=`pwd`
cd $CURDIR
echo Jason home is $JASON_HOME
fi

echo Jason home is $JASON_HOME

if [ -z $JDK_HOME ] ; then
if [ -n $JAVA_HOME ] ; then
JDK_HOME=$JAVA_HOME
Expand Down Expand Up @@ -48,3 +48,10 @@ if [ ! -f $JADE_JAR ] ; then
echo Value is $JADE_JAR
fi

if [ ! -d "$HOME/.jason" ] ; then
echo ----------------------------------------------------------------
echo Jason is not configured in your System
echo run the following command to create a default configuration:
echo java -cp $JASON_JAR jason.util.Config
echo ----------------------------------------------------------------
fi
4 changes: 4 additions & 0 deletions src/main/java/jason/asSyntax/directives/Include.java
Expand Up @@ -37,6 +37,10 @@ public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
// test include from jar
if (file.startsWith("$")) { // the case of "$jasonJar/src/a.asl"
String jar = file.substring(1,file.indexOf("/"));
if (Config.get().get(jar) == null) {
logger.log(Level.SEVERE,"The included file '"+jar+"' is not configured");
return null;
}
String path = Config.get().get(jar).toString();
file = "jar:file:" + path + "!" + file.substring(file.indexOf("/"));
in = new URL(file).openStream();
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/jason/infra/centralised/BaseCentralisedMAS.java
Expand Up @@ -15,12 +15,12 @@ public abstract class BaseCentralisedMAS {
public final static String stopMASFileName = ".stop___MAS";
public final static String defaultProjectFileName = "default.mas2j";

protected static Logger logger = Logger.getLogger(BaseCentralisedMAS.class.getName());
protected static Logger logger = Logger.getLogger(BaseCentralisedMAS.class.getName());
protected static BaseCentralisedMAS runner = null;
protected static String urlPrefix = "";
protected static boolean readFromJAR = false;
protected static MAS2JProject project;
protected static boolean debug = false;
protected static String urlPrefix = "";
protected static boolean readFromJAR = false;
protected static MAS2JProject project;
protected static boolean debug = false;

protected CentralisedEnvironment env = null;
protected CentralisedExecutionControl control = null;
Expand Down Expand Up @@ -76,5 +76,4 @@ public Map<String,CentralisedAgArch> getAgs() {

public abstract void enableDebugControl();


}
14 changes: 9 additions & 5 deletions src/main/java/jason/infra/centralised/RunCentralisedMAS.java
Expand Up @@ -65,8 +65,7 @@ public boolean hasDebugControl(){

public void enableDebugControl(){
btDebug.setEnabled(true);
}

}

public static void main(String[] args) throws JasonException {
RunCentralisedMAS r = new RunCentralisedMAS();
Expand All @@ -86,15 +85,20 @@ protected int init(String[] args) {
readFromJAR = true;
Config.get(false); // to void to call fix/store the configuration in this case everything is read from a jar/jnlp file
} else {
/*System.out.println("Jason "+Config.get().getJasonVersion());
System.out.println("Jason "+Config.get().getJasonVersion());
System.err.println("You should inform the MAS project file.");
JOptionPane.showMessageDialog(null,"You should inform the project file as a parameter.\n\nJason version "+Config.get().getJasonVersion()+" library built on "+Config.get().getJasonBuiltDate(),"Jason", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);*/
//JOptionPane.showMessageDialog(null,"You should inform the project file as a parameter.\n\nJason version "+Config.get().getJasonVersion()+" library built on "+Config.get().getJasonBuiltDate(),"Jason", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
} else {
projectFileName = args[0];
}

if (Config.get().getJasonJar() == null) {
System.out.println("Jason is not configured, creating a default configuration");
Config.get().fix();
}

setupLogger();

if (args.length >= 2) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/jason/runtime/RunJasonProject.java
Expand Up @@ -5,6 +5,7 @@
import jason.infra.MASLauncherInfraTier;
import jason.mas2j.MAS2JProject;
import jason.mas2j.parser.mas2j;
import jason.util.Config;

/**
* Run a Jason mas2j project
Expand Down Expand Up @@ -45,7 +46,10 @@ public static void main (String args[]) {
try {
File file = new File(name);
project = parser.mas();
//Config.get().fix();
if (Config.get().getJasonJar() == null) {
System.out.println("Jason is not configured, creating a default configuration");
Config.get().fix();
}
project.setProjectFile(file);
project.setDirectory(file.getAbsoluteFile().getParentFile().getAbsolutePath());
System.out.println("file "+name+" parsed successfully!\n");
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/jason/util/Config.java
Expand Up @@ -71,7 +71,7 @@ public class Config extends Properties {
public static final String KQML_RECEIVED_FUNCTOR = "kqmlReceivedFunctor";
public static final String KQML_PLANS_FILE = "kqmlPlansFile";

private static Config singleton = null;
protected static Config singleton = null;

protected static String configFactory = null;

Expand Down Expand Up @@ -103,7 +103,7 @@ public static Config get(boolean tryToFixConfig) {
}
return singleton;
}

protected Config() {
}

Expand Down Expand Up @@ -376,10 +376,13 @@ public void fix() {
}

// Default infrastructures
setDefaultInfra();
}

private void setDefaultInfra() {
put("infrastructure.Centralised", CentralisedFactory.class.getName());
put("infrastructure.Jade", JadeFactory.class.getName());
//put("infrastructure.JaCaMo", "jacamo.infra.JaCaMoInfrastructureFactory");

//put("infrastructure.JaCaMo", "jacamo.infra.JaCaMoInfrastructureFactory");
}

public void store() {
Expand Down Expand Up @@ -428,7 +431,13 @@ public String[] getAvailableInfrastructures() {
}

public String getInfrastructureFactoryClass(String infraId) {
return get("infrastructure." + infraId).toString();
Object oClass = get("infrastructure." + infraId);
if (oClass == null) {
// try to fix using default configuration
setDefaultInfra();
oClass = get("infrastructure." + infraId);
}
return oClass.toString();
}
public void setInfrastructureFactoryClass(String infraId, String factory) {
put("infrastructure." + infraId, factory);
Expand Down

0 comments on commit c63140a

Please sign in to comment.