Skip to content

Commit b9dbd66

Browse files
committed
WIP: Java 11 or higher. Move nashron to maven profile
1 parent 73e9f11 commit b9dbd66

2 files changed

Lines changed: 141 additions & 29 deletions

File tree

handlebars/pom.xml

Lines changed: 129 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,6 @@
173173
<optional>true</optional>
174174
</dependency>
175175

176-
<!-- Nashorn JS engine -->
177-
<dependency>
178-
<groupId>org.openjdk.nashorn</groupId>
179-
<artifactId>nashorn-core</artifactId>
180-
<version>15.3</version>
181-
</dependency>
182-
183176
<!-- Logging System -->
184177
<dependency>
185178
<groupId>org.slf4j</groupId>
@@ -236,24 +229,10 @@
236229

237230
<properties>
238231
<antlr-version>4.9.2</antlr-version>
232+
<nashorn.version>15.3</nashorn.version>
239233
</properties>
240234

241235
<profiles>
242-
<profile>
243-
<id>Xlint</id>
244-
<build>
245-
<plugins>
246-
<plugin>
247-
<artifactId>maven-compiler-plugin</artifactId>
248-
<configuration>
249-
<compilerArgs>
250-
<arg>-Xlint</arg>
251-
</compilerArgs>
252-
</configuration>
253-
</plugin>
254-
</plugins>
255-
</build>
256-
</profile>
257236
<profile>
258237
<id>coverage</id>
259238
<build>
@@ -312,5 +291,133 @@
312291
</plugins>
313292
</build>
314293
</profile>
294+
295+
<!-- Range jdk version doesn't work, have to set each jdk -->
296+
<profile>
297+
<id>nashorn9</id>
298+
<activation>
299+
<jdk>9</jdk>
300+
</activation>
301+
<dependencies>
302+
<!-- Nashorn JS engine -->
303+
<dependency>
304+
<groupId>org.openjdk.nashorn</groupId>
305+
<artifactId>nashorn-core</artifactId>
306+
<version>${nashorn.version}</version>
307+
</dependency>
308+
</dependencies>
309+
</profile>
310+
<profile>
311+
<id>nashorn10</id>
312+
<activation>
313+
<jdk>10</jdk>
314+
</activation>
315+
<dependencies>
316+
<!-- Nashorn JS engine -->
317+
<dependency>
318+
<groupId>org.openjdk.nashorn</groupId>
319+
<artifactId>nashorn-core</artifactId>
320+
<version>${nashorn.version}</version>
321+
</dependency>
322+
</dependencies>
323+
</profile>
324+
<profile>
325+
<id>nashorn11</id>
326+
<activation>
327+
<jdk>11</jdk>
328+
</activation>
329+
<dependencies>
330+
<!-- Nashorn JS engine -->
331+
<dependency>
332+
<groupId>org.openjdk.nashorn</groupId>
333+
<artifactId>nashorn-core</artifactId>
334+
<version>${nashorn.version}</version>
335+
</dependency>
336+
</dependencies>
337+
</profile>
338+
<profile>
339+
<id>nashorn12</id>
340+
<activation>
341+
<jdk>12</jdk>
342+
</activation>
343+
<dependencies>
344+
<!-- Nashorn JS engine -->
345+
<dependency>
346+
<groupId>org.openjdk.nashorn</groupId>
347+
<artifactId>nashorn-core</artifactId>
348+
<version>${nashorn.version}</version>
349+
</dependency>
350+
</dependencies>
351+
</profile>
352+
<profile>
353+
<id>nashorn13</id>
354+
<activation>
355+
<jdk>13</jdk>
356+
</activation>
357+
<dependencies>
358+
<!-- Nashorn JS engine -->
359+
<dependency>
360+
<groupId>org.openjdk.nashorn</groupId>
361+
<artifactId>nashorn-core</artifactId>
362+
<version>${nashorn.version}</version>
363+
</dependency>
364+
</dependencies>
365+
</profile>
366+
<profile>
367+
<id>nashorn14</id>
368+
<activation>
369+
<jdk>14</jdk>
370+
</activation>
371+
<dependencies>
372+
<!-- Nashorn JS engine -->
373+
<dependency>
374+
<groupId>org.openjdk.nashorn</groupId>
375+
<artifactId>nashorn-core</artifactId>
376+
<version>${nashorn.version}</version>
377+
</dependency>
378+
</dependencies>
379+
</profile>
380+
<profile>
381+
<id>nashorn15</id>
382+
<activation>
383+
<jdk>15</jdk>
384+
</activation>
385+
<dependencies>
386+
<!-- Nashorn JS engine -->
387+
<dependency>
388+
<groupId>org.openjdk.nashorn</groupId>
389+
<artifactId>nashorn-core</artifactId>
390+
<version>${nashorn.version}</version>
391+
</dependency>
392+
</dependencies>
393+
</profile>
394+
<profile>
395+
<id>nashorn16</id>
396+
<activation>
397+
<jdk>16</jdk>
398+
</activation>
399+
<dependencies>
400+
<!-- Nashorn JS engine -->
401+
<dependency>
402+
<groupId>org.openjdk.nashorn</groupId>
403+
<artifactId>nashorn-core</artifactId>
404+
<version>${nashorn.version}</version>
405+
</dependency>
406+
</dependencies>
407+
</profile>
408+
<profile>
409+
<id>nashorn17</id>
410+
<activation>
411+
<jdk>17</jdk>
412+
</activation>
413+
<dependencies>
414+
<!-- Nashorn JS engine -->
415+
<dependency>
416+
<groupId>org.openjdk.nashorn</groupId>
417+
<artifactId>nashorn-core</artifactId>
418+
<version>${nashorn.version}</version>
419+
</dependency>
420+
</dependencies>
421+
</profile>
315422
</profiles>
316423
</project>

handlebars/src/main/java/com/github/jknack/handlebars/internal/BaseTemplate.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import java.io.IOException;
2626
import java.io.Writer;
2727
import java.lang.invoke.MethodHandles;
28-
import java.lang.invoke.MethodType;
28+
import java.lang.reflect.Constructor;
2929
import java.lang.reflect.InvocationHandler;
3030
import java.lang.reflect.Method;
3131
import java.lang.reflect.Modifier;
@@ -264,12 +264,17 @@ private boolean isDefault(final Method method) {
264264

265265
private Object invokeDefaultMethod(final Method method, final Class<?> lookupClass,
266266
final Object proxy, final Object... args) throws Throwable {
267-
MethodType methodType = MethodType.methodType(method.getReturnType(),
268-
method.getParameterTypes());
269-
return MethodHandles.lookup()
270-
.findSpecial(lookupClass, method.getName(), methodType, lookupClass)
271-
.bindTo(proxy)
272-
.invokeWithArguments(args);
267+
// Jumping through these hoops is needed because calling unreflectSpecial requires that
268+
// the lookup instance have private access to the special caller. None of the static
269+
// factory methods for Lookup will give us an instance with the access modes we need,
270+
// so we work around it by calling the private constructor via reflection.
271+
Constructor<MethodHandles.Lookup> constructor = MethodHandles.Lookup.class
272+
.getDeclaredConstructor(Class.class, int.class);
273+
constructor.setAccessible(true);
274+
return constructor.newInstance(lookupClass, -1 /* trusted */)
275+
.unreflectSpecial(method, lookupClass)
276+
.bindTo(proxy)
277+
.invokeWithArguments(args);
273278
}
274279

275280
@Override

0 commit comments

Comments
 (0)