List of usage examples for org.apache.maven.model.profile ProfileActivationContext getSystemProperties
Map<String, String> getSystemProperties();
From source file:com.coutemeier.maven.jsr223.profileactivator.JSR223ProfileActivator.java
License:Open Source License
private boolean evaluateExpression(Profile profile, ProfileActivationContext context, ModelProblemCollector problemCollector) { Activation activation = profile.getActivation(); ActivationProperty property = activation.getProperty(); String engineName = property.getName().substring(1); String script = property.getValue(); if (engineName == null || engineName.trim().length() == 0) { engineName = DEFAULT_SCRIPT_ENGINE_NAME; }//from ww w . j a v a 2s . c om // create a JavaScript engine ScriptEngine engine = ScriptEngineHelper.getEngine(engineName); // We haven't foud a script engine, so we can't evaluate the script if (engine == null) { final String message = "[JSR223ProfileActivator] Script engine unknown " + profile.getId(); logger.debug(message); problemCollector.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE).setMessage(message) .setLocation(property.getLocation(""))); return false; } logger.debug("[JSR223ProfileActivator] ScriptEngine {}. Trying to evaluate the expression {}", engineName, script); String name = ScriptEngineHelper.getPropertyNameForJSR223(context); engine.put(name, new ExpressionManager(context.getSystemProperties(), context.getProjectProperties(), context.getUserProperties())); try { Object value = engine.eval(script); logger.debug("[JSR223ProfileActivator] Expression evaluated value: {}", value); return true; } catch (ScriptException cause) { final String message = "[JSR223ProfileActivator] There has been an error evaluating the expression in the profile " + profile.getId() + ": " + cause.getMessage(); logger.debug(message); problemCollector.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE).setMessage(message) .setLocation(property.getLocation(""))); } return false; }
From source file:com.coutemeier.maven.jsr223.profileactivator.ScriptEngineHelper.java
License:Open Source License
/** * Returns the name of the variable which will be created to use the interpolator in the script. * The priority of the search is as following: * <ol>//from w w w. j av a2 s. com * <li>If <code>JSR223_PROPERTY_NAME</code> exists in system properties, then return it.</li> * <li>If <code>JSR223_PROPERTY_NAME</code> exists in project properties, then return it.</li> * <li>Return <code>JSR223_PROPERTY_NAME_DEFAULT (<b>aitor</b>) as the name of the variable.</li> * <ol> * * @param context the context of the profile activation section of the pom. * @return the name of the variable present in system properties or project properties, or <code>aitor</code> if * doesn't exists none of them. * @since 0.1.0 */ public static final String getPropertyNameForJSR223(ProfileActivationContext context) { String name = context.getSystemProperties().get(JSR223_PROPERTY_NAME); if (name == null || name.trim().length() == 0) { name = context.getProjectProperties().get(JSR223_PROPERTY_NAME); } if (name == null || name.trim().length() == 0) { name = JSR223_PROPERTY_NAME_DEFAULT; } return name; }
From source file:com.github.sviperll.maven.profiledep.ActivatingProfileSelector.java
private ProfileActivationContext createProfileActivationContext(ProfileActivationContext source) { DefaultProfileActivationContext result = new DefaultProfileActivationContext(); result.setProjectDirectory(source.getProjectDirectory()); Properties projectProperties = new Properties(); projectProperties.putAll(source.getProjectProperties()); result.setProjectProperties(projectProperties); result.setSystemProperties(source.getSystemProperties()); result.setUserProperties(source.getUserProperties()); List<String> activeProfileIds = new ArrayList<String>(); activeProfileIds.addAll(source.getActiveProfileIds()); activeProfileIds.addAll(additionalProfileIDs); result.setActiveProfileIds(activeProfileIds); List<String> inactiveProfileIds = new ArrayList<String>(); inactiveProfileIds.addAll(source.getInactiveProfileIds()); inactiveProfileIds.addAll(additionallyExcludedProfileIDs); result.setInactiveProfileIds(inactiveProfileIds); return result; }
From source file:com.github.sviperll.maven.profiledep.ContextModifyingProfileSelector.java
private ProfileActivationContext createProfileActivationContext(ProfileActivationContext source) { DefaultProfileActivationContext result = new DefaultProfileActivationContext(); result.setProjectDirectory(source.getProjectDirectory()); Properties projectProperties = new Properties(); projectProperties.putAll(source.getProjectProperties()); result.setProjectProperties(projectProperties); result.setSystemProperties(source.getSystemProperties()); result.setUserProperties(source.getUserProperties()); List<String> activeProfileIds = new ArrayList<String>(); activeProfileIds.addAll(additionalProfileIDs); activeProfileIds.removeAll(source.getInactiveProfileIds()); activeProfileIds.addAll(source.getActiveProfileIds()); result.setActiveProfileIds(activeProfileIds); List<String> inactiveProfileIds = new ArrayList<String>(); inactiveProfileIds.addAll(additionallyExcludedProfileIDs); inactiveProfileIds.removeAll(source.getActiveProfileIds()); inactiveProfileIds.addAll(source.getInactiveProfileIds()); result.setInactiveProfileIds(inactiveProfileIds); return result; }
From source file:com.redhat.jboss.maven.elprofile.ElProfileActivator.java
License:Apache License
private boolean evaluateMvel(String expression, ProfileActivationContext context, ModelProblemCollector problemCollector) { if (expression == null || expression.length() == 0) { return false; }/*from w ww .j ava 2s . c o m*/ try { // "casting" to <String,Object> and including both user and system properties Map<String, Object> externalVariables = new HashMap<String, Object>(); externalVariables.putAll(context.getSystemProperties()); externalVariables.putAll(context.getUserProperties()); return MVEL.evalToBoolean(expression, externalVariables); } catch (NullPointerException e) { logger.warn("Unable to evaluate mvel property value (\"" + expression + "\")"); logger.debug(e.getMessage()); return false; } catch (CompileException e) { logger.warn("Unable to evaluate mvel property value (\"" + expression + "\")"); logger.debug(e.getMessage()); return false; } }