List of usage examples for org.apache.maven.plugin PluginParameterExpressionEvaluator evaluate
@Override public Object evaluate(String expr) throws ExpressionEvaluationException
From source file:com.github.zdsiyan.maven.plugin.smartconfig.SmartconfigMojo.java
License:Apache License
private Smartconfig buildFastconfig() throws Exception { PluginParameterExpressionEvaluator pel = new PluginParameterExpressionEvaluator(session, execution); Smartconfig fastconfig = new Smartconfig(); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(config); Element root = doc.getRootElement(); // use scriptEngine, maybe we can extend it, not only javascript ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("javascript"); // load profile List<Profile> profiles = session.getCurrentProject().getActiveProfiles(); profiles.forEach(profile -> profile.getProperties().keySet().forEach(key -> { Object value = profile.getProperties().get(key); engine.put(key.toString(), value); //getLog().warn("profile:"+key); }));/*from w ww . j av a2s .c om*/ // load user properties session.getUserProperties().keySet().forEach(key -> { Object value = session.getUserProperties().get(key); engine.put(key.toString(), value); //getLog().warn("user:"+key); }); /* load sys properties session.getSystemProperties().keySet().forEach(key->{ Object value = session.getSystemProperties().get(key); engine.put(key.toString(), value); getLog().warn("sys:"+key); }); */ session.getCurrentProject().getProperties().keySet().forEach(key -> { Object value = session.getCurrentProject().getProperties().get(key); engine.put(key.toString(), value); //getLog().warn("prop:"+key); }); // config-file for (Element cf : root.getChildren()) { String path = String.valueOf(pel.evaluate(cf.getAttributeValue("path"))); File file = new File(path); if (!file.isAbsolute()) { file = new File(outputDirectory, path); } boolean disable = false; //eval the script if (StringUtils.isNotEmpty(cf.getAttributeValue("disable"))) { Object result = engine.eval(cf.getAttributeValue("disable")); if (Boolean.TRUE.equals(result)) { disable = true; } } if (disable == true) { continue; } //rename to if (StringUtils.isNotEmpty(cf.getAttributeValue("replace"))) { String replace = String.valueOf(pel.evaluate(cf.getAttributeValue("replace"))); //getLog().warn("filepath:"+file.getPath()); File refile = new File(file.getParent() + File.separator + replace); //getLog().warn("refilepath:"+refile.getPath()); FileUtils.rename(file, refile); continue; } ConfigFile.Mode mode; if (StringUtils.isNotEmpty(cf.getAttributeValue("mode"))) { mode = ConfigFile.Mode.valueOf(cf.getAttributeValue("mode")); } else { mode = toConfigMode(path.substring(path.lastIndexOf(".") + 1)); } if (mode == null) { throw new SmartconfigException("Not found file[" + path + "] replace mode"); } ConfigFile configFile = new ConfigFile(file, mode); for (Element rt : cf.getChildren()) { String expression = rt.getAttributeValue("expression"); String value = String.valueOf(pel.evaluate(rt.getTextTrim())); PointHandle.Mode phMode; if (StringUtils.isNotEmpty(rt.getAttributeValue("mode"))) { phMode = PointHandle.Mode.valueOf(rt.getAttributeValue("mode")); } else { phMode = PointHandle.Mode.replace; } if (mode == null) { throw new SmartconfigException("Not found pointhandle mode"); } configFile.addPointHandle(new PointHandle(expression, value, phMode)); } fastconfig.addConfigFile(configFile); } return fastconfig; }
From source file:org.skfiy.maven.plugin.fastconfig.FastconfigMojo.java
License:Apache License
private Fastconfig buildFastconfig() throws Exception { PluginParameterExpressionEvaluator pel = new PluginParameterExpressionEvaluator(session, execution); Fastconfig fastconfig = new Fastconfig(); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(config); Element root = doc.getRootElement(); // config-file for (Element cf : root.getChildren()) { String path = String.valueOf(pel.evaluate(cf.getAttributeValue("path"))); File file = new File(path); if (!file.isAbsolute()) { file = new File(outputDirectory, path); }//from ww w. j ava2s. c o m ConfigFile.Mode mode; if (StringUtils.isNotEmpty(cf.getAttributeValue("mode"))) { mode = ConfigFile.Mode.valueOf(cf.getAttributeValue("mode")); } else { mode = toMode(path.substring(path.lastIndexOf(".") + 1)); } if (mode == null) { throw new FastconfigException("Not found file[" + path + "] replace mode"); } ConfigFile configFile = new ConfigFile(file, mode); // replacement for (Element rt : cf.getChildren()) { String expression = rt.getAttributeValue("expression"); String value = String.valueOf(pel.evaluate(rt.getTextTrim())); configFile.addReplacement(new Replacement(expression, value)); } fastconfig.addConfigFile(configFile); } return fastconfig; }
From source file:org.wildfly.plugins.DeployExtensionMojo.java
License:Open Source License
private Object evalPluginParameterExpression(String expression) { PluginParameterExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator(mavenSession, mojoExecution);// w w w .j a v a2 s . c o m try { return evaluator.evaluate(expression); } catch (ExpressionEvaluationException e) { getLog().error("Failed to evaluate [" + expression + "]", e); } return null; }