From: <jom...@us...> - 2014-09-24 12:59:36
|
Revision: 1809 http://sourceforge.net/p/jason/svn/1809 Author: jomifred Date: 2014-09-24 12:59:32 +0000 (Wed, 24 Sep 2014) Log Message: ----------- improve include to include from a jar file Modified Paths: -------------- trunk/examples/auction/auction.mas2j trunk/examples/contract-net-protocol/p.asl trunk/src/jason/asSyntax/directives/Include.java Modified: trunk/examples/auction/auction.mas2j =================================================================== --- trunk/examples/auction/auction.mas2j 2014-09-23 17:37:34 UTC (rev 1808) +++ trunk/examples/auction/auction.mas2j 2014-09-24 12:59:32 UTC (rev 1809) @@ -1,4 +1,4 @@ -// creates an MAS called auction +// simple implementation of first-price sealed-bid auction MAS auction { Modified: trunk/examples/contract-net-protocol/p.asl =================================================================== --- trunk/examples/contract-net-protocol/p.asl 2014-09-23 17:37:34 UTC (rev 1808) +++ trunk/examples/contract-net-protocol/p.asl 2014-09-24 12:59:32 UTC (rev 1809) @@ -19,8 +19,7 @@ @r1 +accept_proposal(CNPId) : proposal(CNPId,Task,Offer) - <- .print("My proposal '",Offer,"' won CNP ",CNPId, - " for ",Task,"!"). + <- .print("My proposal '",Offer,"' won CNP ",CNPId, " for ",Task,"!"). // do the task and report to initiator @r2 +reject_proposal(CNPId) Modified: trunk/src/jason/asSyntax/directives/Include.java =================================================================== --- trunk/src/jason/asSyntax/directives/Include.java 2014-09-23 17:37:34 UTC (rev 1808) +++ trunk/src/jason/asSyntax/directives/Include.java 2014-09-24 12:59:32 UTC (rev 1809) @@ -4,6 +4,7 @@ import jason.asSyntax.Pred; import jason.asSyntax.StringTerm; import jason.asSyntax.parser.as2j; +import jason.jeditplugin.Config; import java.io.File; import java.io.FileInputStream; @@ -29,40 +30,48 @@ return null; String file = ((StringTerm)directive.getTerm(0)).getString().replaceAll("\\\\", "/"); try { - String outerPrefix = outerContent.getASLSrc(); // the source file that has the include directive - InputStream in; - if (outerContent != null && outerPrefix != null) { - // check if the outer is URL - if (outerPrefix.startsWith("jar")) { - outerPrefix = outerPrefix.substring(0,outerPrefix.indexOf("!")+1) + "/"; - file = checkPathAndFixWithSourcePath(file, aslSourcePath, outerPrefix); - in = new URL(file).openStream(); - - } if (outerPrefix.startsWith(CRPrefix)) { - // outer is loaded from a resource ("application".jar) file, used for java web start - int posSlash = outerPrefix.lastIndexOf("/"); - - List<String> newpath = new ArrayList<String>(); - if (outerPrefix.indexOf("/") != posSlash) { // has only one slash - newpath.add(outerPrefix.substring(CRPrefix.length()+1,posSlash)); + InputStream in = null; + // test include from jar + if (file.startsWith("$")) { // the case of "$jasonJar/src/a.asl" + String jar = file.substring(1,file.indexOf("/")); + String path = Config.get().get(jar).toString(); + file = "jar:file:" + path + "!" + file.substring(file.indexOf("/")); + in = new URL(file).openStream(); + } else { + String outerPrefix = outerContent.getASLSrc(); // the source file that has the include directive + if (outerContent != null && outerPrefix != null) { + // check if the outer is URL + if (outerPrefix.startsWith("jar")) { + outerPrefix = outerPrefix.substring(0,outerPrefix.indexOf("!")+1) + "/"; + file = checkPathAndFixWithSourcePath(file, aslSourcePath, outerPrefix); + in = new URL(file).openStream(); + + } if (outerPrefix.startsWith(CRPrefix)) { + // outer is loaded from a resource ("application".jar) file, used for java web start + int posSlash = outerPrefix.lastIndexOf("/"); + + List<String> newpath = new ArrayList<String>(); + if (outerPrefix.indexOf("/") != posSlash) { // has only one slash + newpath.add(outerPrefix.substring(CRPrefix.length()+1,posSlash)); + } + newpath.addAll(aslSourcePath); + + file = checkPathAndFixWithSourcePath(file, newpath, CRPrefix+"/"); + in = Agent.class.getResource(file.substring(CRPrefix.length())).openStream(); + } else { + // get the directory of the source of the outer agent and + // try to find the included source in the same directory + // or in the source paths + List<String> newpath = new ArrayList<String>(); + newpath.add(new File(outerPrefix).getAbsoluteFile().getParent()); + if (aslSourcePath != null) + newpath.addAll(aslSourcePath); + file = checkPathAndFixWithSourcePath(file, newpath, null); + in = new FileInputStream(file); } - newpath.addAll(aslSourcePath); - - file = checkPathAndFixWithSourcePath(file, newpath, CRPrefix+"/"); - in = Agent.class.getResource(file.substring(CRPrefix.length())).openStream(); } else { - // get the directory of the source of the outer agent and - // try to find the included source in the same directory - // or in the source paths - List<String> newpath = new ArrayList<String>(); - newpath.add(new File(outerPrefix).getAbsoluteFile().getParent()); - if (aslSourcePath != null) - newpath.addAll(aslSourcePath); - file = checkPathAndFixWithSourcePath(file, newpath, null); - in = new FileInputStream(file); + in = new FileInputStream(checkPathAndFixWithSourcePath(file, aslSourcePath, null)); } - } else { - in = new FileInputStream(checkPathAndFixWithSourcePath(file, aslSourcePath, null)); } Agent ag = new Agent(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |