Skip to content

Commit

Permalink
correct classpath loader is set in EvalDataLoader;
Browse files Browse the repository at this point in the history
Fix for path resolution in FileUtil when path is already absolute
(otherwise it's corrupted  on Windows)
  • Loading branch information
Vitaly Dyachkov committed Nov 18, 2019
1 parent 89e7473 commit 3d9bf2a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 54 deletions.
107 changes: 54 additions & 53 deletions src/main/java/fmpp/dataloaders/EvalDataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>Engine</code> object by the
* <code>engine</code> 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 <code>Engine</code> object by the
* <code>engine</code> 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);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/fmpp/tools/AntTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>Mapper</code> value.
* @since 0.9.16
*/
public void addMapper(Mapper mapper) {
if (this.mapper != null) {
Expand All @@ -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());
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/fmpp/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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("/")) {
Expand Down

0 comments on commit 3d9bf2a

Please sign in to comment.