Skip to content

Commit 1c3f0e2

Browse files
committed
add maven support for functions
1 parent 110d788 commit 1c3f0e2

File tree

5 files changed

+47
-7
lines changed

5 files changed

+47
-7
lines changed

core/src/main/java/lucee/runtime/functions/FunctionHandlerPool.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import lucee.runtime.listener.JavaSettingsImpl;
2828
import lucee.runtime.op.Caster;
2929
import lucee.runtime.reflection.Reflector;
30+
import lucee.transformer.library.ClassDefinitionImpl;
3031

3132
// TODO kann man nicht auf context ebene
3233

@@ -44,6 +45,10 @@ public static Object invoke(PageContext pc, Object[] args, String className) thr
4445
return use(pc, className).invoke(pc, args);
4546
}
4647

48+
public static Object invoke(PageContext pc, Object[] args, String className, String maven) throws PageException {
49+
return use(pc, className, maven).invoke(pc, args);
50+
}
51+
4752
/**
4853
* return a tag to use from a class
4954
*
@@ -77,6 +82,32 @@ public static BIF use(PageContext pc, String className, String bundleName, Strin
7782
return bif;
7883
}
7984

85+
public static BIF use(PageContext pc, String className, String maven) throws PageException {
86+
String id = toId(className, maven, null);
87+
BIF bif = map.get(id);
88+
if (bif != null) return bif;
89+
90+
try {
91+
Class<?> clazz;
92+
// Maven
93+
if (!StringUtil.isEmpty(maven)) {
94+
clazz = new ClassDefinitionImpl(className, maven).getClazz();
95+
}
96+
// JAR
97+
else {
98+
clazz = ClassUtil.loadClass(pc, className);
99+
}
100+
101+
if (Reflector.isInstaneOf(clazz, BIF.class, false)) bif = (BIF) ClassUtil.newInstance(clazz);
102+
else bif = new BIFProxy(clazz);
103+
}
104+
catch (Exception e) {
105+
throw Caster.toPageException(e);
106+
}
107+
map.put(id, bif);
108+
return bif;
109+
}
110+
80111
public static BIF use(PageContext pc, String className) throws PageException {
81112
BIF bif = map.get(className);
82113
if (bif != null) return bif;

core/src/main/java/lucee/transformer/bytecode/expression/var/VariableImpl.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import lucee.transformer.expression.var.NamedMember;
7272
import lucee.transformer.expression.var.Variable;
7373
import lucee.transformer.interpreter.literal.LitStringImpl;
74+
import lucee.transformer.library.ClassDefinitionImpl;
7475
import lucee.transformer.library.function.FunctionLibFunction;
7576
import lucee.transformer.library.function.FunctionLibFunctionArg;
7677
import lucee.transformer.library.tag.TagLibTag;
@@ -127,6 +128,7 @@ public final class VariableImpl extends ExpressionBase implements Variable {
127128
private static final Method STATIC_GET1 = new Method("staticGet", Types.OBJECT, new Type[] { Types.OBJECT });
128129
private static final Method STATIC_TOUCH1 = new Method("staticTouch", Types.OBJECT, new Type[] { Types.OBJECT });
129130
private static final Method INVOKE3 = new Method("invoke", Types.OBJECT, new Type[] { Types.PAGE_CONTEXT, Types.OBJECT_ARRAY, Types.STRING });
131+
private static final Method INVOKE4 = new Method("invoke", Types.OBJECT, new Type[] { Types.PAGE_CONTEXT, Types.OBJECT_ARRAY, Types.STRING, Types.STRING });
130132
private static final Method INVOKE5 = new Method("invoke", Types.OBJECT, new Type[] { Types.PAGE_CONTEXT, Types.OBJECT_ARRAY, Types.STRING, Types.STRING, Types.STRING });
131133

132134
// GET
@@ -549,8 +551,7 @@ static Type _writeOutFirstBIF(BytecodeContext bc, BIF bif, int mode, boolean las
549551
try {
550552
if (clazzz.getMethods("call", true, -1).size() == 0) core = false;
551553
}
552-
catch (Exception e) {
553-
}
554+
catch (Exception e) {}
554555
}
555556
// load method
556557
List<lucee.transformer.dynamic.meta.Method> methods = null;
@@ -559,8 +560,7 @@ static Type _writeOutFirstBIF(BytecodeContext bc, BIF bif, int mode, boolean las
559560
methods = clazzz.getMethods("call", true, args.length + 1);
560561
if (methods != null && methods.size() == 0) methods = null;
561562
}
562-
catch (Exception e) {
563-
}
563+
catch (Exception e) {}
564564
}
565565

566566
if (bif.getArgType() == FunctionLibFunction.ARG_FIX && !bifCD.isBundle() && core) {
@@ -719,9 +719,14 @@ static Type _writeOutFirstBIF(BytecodeContext bc, BIF bif, int mode, boolean las
719719
else ASMConstants.NULL(adapter);
720720
if (bifCD.getVersionAsString() != null) adapter.push(bifCD.getVersionAsString());// bundle version
721721
else ASMConstants.NULL(adapter);
722-
723722
adapter.invokeStatic(Types.FUNCTION_HANDLER_POOL, INVOKE5);
724723
}
724+
else if (((ClassDefinitionImpl) bifCD).isMaven()) {
725+
adapter.push(((ClassDefinitionImpl) bifCD).getMavenRaw());// maven data
726+
727+
adapter.invokeStatic(Types.FUNCTION_HANDLER_POOL, INVOKE4);
728+
}
729+
725730
else adapter.invokeStatic(Types.FUNCTION_HANDLER_POOL, INVOKE3);
726731
rtnType = Types.OBJECT;
727732
}

core/src/main/java/lucee/transformer/library/ClassDefinitionImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ public GAVSO[] getMaven() throws ApplicationException {
328328
return gavsos;
329329
}
330330

331+
public String getMavenRaw() {
332+
return maven;
333+
}
334+
331335
@Override
332336
public boolean hasVersion() {
333337
return version != null;

loader/build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<project default="core" basedir="." name="Lucee"
33
xmlns:resolver="antlib:org.apache.maven.resolver.ant">
44

5-
<property name="version" value="7.0.2.86-SNAPSHOT"/>
5+
<property name="version" value="7.0.2.87-SNAPSHOT"/>
66

77
<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
88
<classpath>

loader/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>org.lucee</groupId>
55
<artifactId>lucee</artifactId>
6-
<version>7.0.2.86-SNAPSHOT</version>
6+
<version>7.0.2.87-SNAPSHOT</version>
77
<packaging>jar</packaging>
88

99
<name>Lucee Loader Build</name>

0 commit comments

Comments
 (0)