private void addProjectDependenciesToClassRealm(ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm) throws ComponentConfigurationException { List<String> compileClasspathElements; try { //noinspection unchecked compileClasspathElements = (List<String>) expressionEvaluator.evaluate("${project.compileClasspathElements}"); } catch (ExpressionEvaluationException e) { throw new ComponentConfigurationException("There was a problem evaluating: ${project.compileClasspathElements}", e); } // Add the project dependencies to the ClassRealm final URL[] urls = buildURLs(compileClasspathElements); for (URL url : urls) { containerRealm.addURL(url); } }
public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type, Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator, ConfigurationListener listener ) throws ComponentConfigurationException { File f = (File) super.fromConfiguration( converterLookup, configuration, type, baseType, classLoader, expressionEvaluator, listener ); if ( f != null ) { // Hmmm... is this cheating? Can't think of a better way right now return expressionEvaluator.alignToBaseDirectory( f ); } else { return null; } } }
// Compile the expression once; relatively slow. ExpressionEvaluator ee = new ExpressionEvaluator( "sin(x)", // expression double.class, // expressionType new String[] { "x" }, // parameterNames new Class[] { double.class } // parameterTypes ); // Evaluate it with varying parameter values; very fast. Double res = (Integer) ee.evaluate( new Object[] { // parameterValues new Double(12.34) } ); System.out.println("result = " + res);
// Compile the expression once; relatively slow. ExpressionEvaluator ee = new ExpressionEvaluator( "c > d ? c : d", // expression int.class, // expressionType new String[] { "c", "d" }, // parameterNames new Class[] { int.class, int.class } // parameterTypes ); // Evaluate it with varying parameter values; very fast. Integer res = (Integer) ee.evaluate( new Object[] { // parameterValues new Integer(10), new Integer(11), } ); System.out.println("res = " + res);
private void addProjectDependenciesToClassRealm(ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm) throws ComponentConfigurationException { List<String> runtimeClasspathElements; try { // noinspection unchecked runtimeClasspathElements = (List<String>) expressionEvaluator .evaluate("${project.runtimeClasspathElements}"); } catch (ExpressionEvaluationException e) { throw new ComponentConfigurationException( "There was a problem evaluating: ${project.runtimeClasspathElements}", e); } // Add the project dependencies to the ClassRealm final URL[] urls = buildURLs(runtimeClasspathElements); for (URL url : urls) { containerRealm.addConstituent(url); } }
import java.lang.reflect.InvocationTargetException; import org.codehaus.commons.compiler.CompileException; import org.codehaus.janino.ExpressionEvaluator; public class WorkSheet_1{ public static void main(String[] args) throws CompileException, InvocationTargetException { ExpressionEvaluator ee = new ExpressionEvaluator( "a != 0 && b > 5", boolean.class, new String[] { "a", "b" }, new Class[] { int.class, int.class } ); Boolean res1 = (Boolean) ee.evaluate(new Object[] {new Integer(2), new Integer(6),}); System.out.println("res1 = " + res1); Boolean res2 = (Boolean) ee.evaluate(new Object[] {new Integer(2), new Integer(5),}); System.out.println("res2 = " + res2); } }
@Override public File alignToBaseDirectory( File theFile ) { return evaluator.alignToBaseDirectory( theFile ); }
value = expressionEvaluator.evaluate( expression );
/** * Align a given path to the base directory that can be evaluated by this expression evaluator, if known. * * @param file the file * @return the aligned file */ public File alignToBaseDirectory(File file) { return evaluator.alignToBaseDirectory(file); } }
private void addProjectDependenciesToClassRealm(ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm) throws ComponentConfigurationException { List<String> compileClasspathElements; try { //noinspection unchecked compileClasspathElements = (List<String>) expressionEvaluator.evaluate("${project.compileClasspathElements}"); } catch (ExpressionEvaluationException e) { throw new ComponentConfigurationException("There was a problem evaluating: ${project.compileClasspathElements}", e); } // Add the project dependencies to the ClassRealm final URL[] urls = buildURLs(compileClasspathElements); for (URL url : urls) { containerRealm.addConstituent(url); } }
public File alignToBaseDirectory( File theFile ) { return evaluator.alignToBaseDirectory( theFile ); }
@Override public Object fromConfiguration( final ConverterLookup lookup, final PlexusConfiguration configuration, final Class<?> type, final Class<?> enclosingType, final ClassLoader loader, final ExpressionEvaluator evaluator, final ConfigurationListener listener ) throws ComponentConfigurationException { final Object result = super.fromConfiguration( lookup, configuration, type, enclosingType, loader, evaluator, listener ); return result instanceof File ? evaluator.alignToBaseDirectory( (File) result ) : result; } }
public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type, Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator, ConfigurationListener listener ) throws ComponentConfigurationException { File f = (File) super.fromConfiguration( converterLookup, configuration, type, baseType, classLoader, expressionEvaluator, listener ); if ( f != null ) { // Hmmm... is this cheating? Can't think of a better way right now return expressionEvaluator.alignToBaseDirectory( f ); } else { return null; } } }
@Override public Object evaluate( String theExpression ) throws ExpressionEvaluationException { return evaluator.evaluate( theExpression ); }
/** * Returns the location of test reports created by the specified MOJO. * @param pom The project model. * @param mojo The MOJO. * @return The directory containing the test reports. * @throws ComponentConfigurationException if unable to retrieve the report directory from the MOJO configuration. */ @Nonnull protected File getReportsDirectory(MavenProject pom, MojoInfo mojo) throws ComponentConfigurationException { // [JENKINS-31258] Allow unknown MOJOs to contribute test results in arbitrary locations by setting a Maven property. String reportsDirectoryOverride = getReportsDirectoryOverride(mojo); if (reportsDirectoryOverride != null) return mojo.expressionEvaluator.alignToBaseDirectory(new File(reportsDirectoryOverride)); if (this.reportDirectoryConfigKey != null) { File reportsDir = mojo.getConfigurationValue(this.reportDirectoryConfigKey, File.class); if (reportsDir != null) return reportsDir; } // some plugins just default to this: return new File(pom.getBuild().getDirectory(), "surefire-reports"); }
public Object evaluate( String theExpression ) throws ExpressionEvaluationException { return evaluator.evaluate( theExpression ); }
/** * Evaluate an expression. * * @param expression the expression * @return the value of the expression */ public Object evaluate(String expression) throws ExpressionEvaluationException { return evaluator.evaluate(expression); }
private List<String> lookupRuntimeClasspathElements(ExpressionEvaluator expressionEvaluator) throws ComponentConfigurationException { List<String> runtimeClasspathElements; try { //noinspection unchecked runtimeClasspathElements = (List<String>) expressionEvaluator.evaluate("${project.runtimeClasspathElements}"); } catch (ExpressionEvaluationException e) { throw new ComponentConfigurationException("There was a problem evaluating: ${project.runtimeClasspathElements}", e); } return runtimeClasspathElements; }