From 3d9bf2a4521ea804787799fbd5f9653064e8a534 Mon Sep 17 00:00:00 2001 From: Vitaly Dyachkov Date: Tue, 22 Jan 2019 15:34:27 +0200 Subject: [PATCH] correct classpath loader is set in EvalDataLoader; Fix for path resolution in FileUtil when path is already absolute (otherwise it's corrupted on Windows) --- .../java/fmpp/dataloaders/EvalDataLoader.java | 107 +++++++++--------- src/main/java/fmpp/tools/AntTask.java | 3 +- src/main/java/fmpp/util/FileUtil.java | 6 + 3 files changed, 62 insertions(+), 54 deletions(-) diff --git a/src/main/java/fmpp/dataloaders/EvalDataLoader.java b/src/main/java/fmpp/dataloaders/EvalDataLoader.java index 2415f9d..1d5cea0 100644 --- a/src/main/java/fmpp/dataloaders/EvalDataLoader.java +++ b/src/main/java/fmpp/dataloaders/EvalDataLoader.java @@ -14,56 +14,57 @@ * limitations under the License. */ -package fmpp.dataloaders; - -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import bsh.Interpreter; -import fmpp.Engine; -import fmpp.tdd.DataLoader; - -/** - * Evaluates a BeanShell expression (looks like as Java). - * The scrip has access to the Engine object by the - * engine variable. - */ -public class EvalDataLoader implements DataLoader { - public Object load(Engine e, List args) throws Exception { - int ln = args.size(); - if (ln < 1 || ln > 2) { - throw new IllegalArgumentException( - "eval(script[, vars]) needs 1 or 2 arguments."); - } - String script; - Object o = args.get(0); - if (!(o instanceof String)) { - throw new IllegalArgumentException( - "The 1st parameter to eval(script[, vars])" + "must be a string, but it was a " - + fmpp.tdd.Interpreter.getTypeName(o) + "."); - } - script = (String) o; - - Interpreter intp = new Interpreter(); - intp.set("engine", e); - - if (ln > 1) { - o = args.get(1); - if (!(o instanceof Map)) { - throw new IllegalArgumentException( - "The 2nd parameter to eval(script[, vars])" - + "must be a hash, but it was a " - + fmpp.tdd.Interpreter.getTypeName(o) + "."); - } - Map vars = (Map) o; - Iterator it = vars.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry ent = (Map.Entry) it.next(); - intp.set((String) ent.getKey(), ent.getValue()); - } - } - - return intp.eval(script); - } -} +package fmpp.dataloaders; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import bsh.Interpreter; +import fmpp.Engine; +import fmpp.tdd.DataLoader; + +/** + * Evaluates a BeanShell expression (looks like as Java). + * The scrip has access to the Engine object by the + * engine variable. + */ +public class EvalDataLoader implements DataLoader { + public Object load(Engine e, List args) throws Exception { + int ln = args.size(); + if (ln < 1 || ln > 2) { + throw new IllegalArgumentException( + "eval(script[, vars]) needs 1 or 2 arguments."); + } + String script; + Object o = args.get(0); + if (!(o instanceof String)) { + throw new IllegalArgumentException( + "The 1st parameter to eval(script[, vars])" + "must be a string, but it was a " + + fmpp.tdd.Interpreter.getTypeName(o) + "."); + } + script = (String) o; + + Interpreter intp = new Interpreter(); + intp.set("engine", e); + intp.setClassLoader(this.getClass().getClassLoader()); + + if (ln > 1) { + o = args.get(1); + if (!(o instanceof Map)) { + throw new IllegalArgumentException( + "The 2nd parameter to eval(script[, vars])" + + "must be a hash, but it was a " + + fmpp.tdd.Interpreter.getTypeName(o) + "."); + } + Map vars = (Map) o; + Iterator it = vars.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry ent = (Map.Entry) it.next(); + intp.set((String) ent.getKey(), ent.getValue()); + } + } + + return intp.eval(script); + } +} diff --git a/src/main/java/fmpp/tools/AntTask.java b/src/main/java/fmpp/tools/AntTask.java index 1db3db7..cb1092b 100644 --- a/src/main/java/fmpp/tools/AntTask.java +++ b/src/main/java/fmpp/tools/AntTask.java @@ -61,6 +61,7 @@ public class AntTask extends org.apache.tools.ant.taskdefs.MatchingTask { * Add a mapper to convert the file names. * * @param mapper a Mapper value. + * @since 0.9.16 */ public void addMapper(Mapper mapper) { if (this.mapper != null) { @@ -73,7 +74,7 @@ public void addMapper(Mapper mapper) { /** * Add a nested filenamemapper. * @param fileNameMapper the mapper to add. - * @since Ant 1.6.3 + * @since 0.9.16 */ public void add(FileNameMapper fileNameMapper) { Mapper m = new Mapper(getProject()); diff --git a/src/main/java/fmpp/util/FileUtil.java b/src/main/java/fmpp/util/FileUtil.java index 98f693e..0ce9aaf 100644 --- a/src/main/java/fmpp/util/FileUtil.java +++ b/src/main/java/fmpp/util/FileUtil.java @@ -174,6 +174,12 @@ public static boolean isInside(File file, File ascendant) { */ public static File resolveRelativeUnixPath(File root, File wd, String path) throws IOException { + + File isAbsolute = new File(path); + if(isAbsolute.isAbsolute()) { + return isAbsolute; + } + File c; int i; if (path.startsWith("/")) {