List of usage examples for org.apache.maven.plugin PluginParameterExpressionEvaluator PluginParameterExpressionEvaluator
public PluginParameterExpressionEvaluator(MavenSession session, MojoExecution mojoExecution)
From source file:com.github.sdedwards.m2e_nar.internal.MavenUtils.java
License:Apache License
private static <T extends AbstractMojo> T getConfiguredMojo(MavenSession session, MojoExecution mojoExecution, Class<T> asType, Log log) throws CoreException { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor(); ClassRealm pluginRealm = getMyRealm(pluginDescriptor.getClassRealm().getWorld()); T mojo;//w ww . j a va 2 s . co m try { mojo = asType.newInstance(); } catch (Exception e) { throw new CoreException( new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Problem when creating mojo", e)); } mojo.setLog(log); logger.debug("Configuring mojo " + mojoDescriptor.getId() + " from plugin realm " + pluginRealm); Xpp3Dom dom = mojoExecution.getConfiguration(); PlexusConfiguration pomConfiguration; if (dom == null) { pomConfiguration = new XmlPlexusConfiguration("configuration"); } else { pomConfiguration = new XmlPlexusConfiguration(dom); } ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(session, mojoExecution); populatePluginFields(mojo, mojoDescriptor, pluginRealm, pomConfiguration, expressionEvaluator); return mojo; }
From source file:com.github.shyiko.sme.ServersExtension.java
License:Apache License
@Override public void afterProjectsRead(MavenSession session) throws MavenExecutionException { MojoExecution mojoExecution = new MojoExecution(new MojoDescriptor()); ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(session, mojoExecution); Properties userProperties = session.getUserProperties(); boolean exportAsSysProp = isExtensionProperty(session, "servers.exportAsSysProp"); Map<String, String> properties = new HashMap<String, String>(); try {/*from w w w. j a v a2 s . com*/ for (Server server : session.getSettings().getServers()) { String serverId = server.getId(); for (String field : FIELDS) { String[] aliases = getAliases(serverId, field); String fieldNameWithFirstLetterCapitalized = upperCaseFirstLetter(field); String fieldValue = (String) Server.class.getMethod("get" + fieldNameWithFirstLetterCapitalized) .invoke(server); if (fieldValue != null) { fieldValue = decryptInlinePasswords(fieldValue); } for (String alias : aliases) { String userPropertyValue = userProperties.getProperty(alias); if (userPropertyValue != null) { fieldValue = userPropertyValue; break; } } String resolvedValue = (String) expressionEvaluator.evaluate(fieldValue); Server.class .getMethod("set" + fieldNameWithFirstLetterCapitalized, new Class[] { String.class }) .invoke(server, resolvedValue); if (resolvedValue != null) { for (String alias : aliases) { properties.put(alias, resolvedValue); } } } } if (exportAsSysProp) { System.getProperties().putAll(properties); } else { for (MavenProject project : session.getProjects()) { Properties projectProperties = project.getProperties(); projectProperties.putAll(properties); } } } catch (Exception e) { throw new MavenExecutionException("Failed to expose settings.servers.*", e); } }
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 w w .j a v a2s. com*/ // 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:com.lewisd.maven.lint.plugin.CheckMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { pluginParameterExpressionEvaluator = new PluginParameterExpressionEvaluator(session, mojoExecution); getContext().getBeanFactory().registerResolvableDependency(PluginParameterExpressionEvaluator.class, pluginParameterExpressionEvaluator); init();//w w w .j ava2s .c o m ResultCollector resultCollector = getContext().getBean(ResultCollector.class); executeRules(resultCollector); List<String> outputReports = fillOutputReports(resultCollector); if (failOnViolation && resultCollector.hasViolations()) { final String message = generateErrorMessage(outputReports); throw new MojoFailureException(message); } }
From source file:com.messapix.ftatr.jfxmobile.maven.plugin.MobileExpressionEvaluator.java
License:Apache License
private ExpressionEvaluator getEvaluator() { if (evaluator == null) { evaluator = new PluginParameterExpressionEvaluator(session, execution); }// w ww . ja v a2 s.co m return evaluator; }
From source file:com.spotify.docker.BuildMojo.java
License:Apache License
@Override protected void execute(final DockerClient docker) throws MojoExecutionException, GitAPIException, IOException, DockerException, InterruptedException { if (skipDockerBuild) { getLog().info("Skipping docker build"); return;//www.j a v a 2 s.com } // Put the list of exposed ports into a TreeSet which will remove duplicates and keep them // in a sorted order. This is useful when we merge with ports defined in the profile. exposesSet = Sets.newTreeSet(exposes); if (runs != null) { runList = Lists.newArrayList(runs); } expressionEvaluator = new PluginParameterExpressionEvaluator(session, execution); final Git git = new Git(); final String commitId = git.isRepository() ? git.getCommitId() : null; if (commitId == null) { final String errorMessage = "Not a git repository, cannot get commit ID. Make sure git repository is initialized."; if (useGitCommitId || ((imageName != null) && imageName.contains("${gitShortCommitId}"))) { throw new MojoExecutionException(errorMessage); } else { getLog().debug(errorMessage); } } else { // Put the git commit id in the project properties. Image names may contain // ${gitShortCommitId} in which case we want to fill in the actual value using the // expression evaluator. We will do that once here for image names loaded from the pom, // and again in the loadProfile method when we load values from the profile. mavenProject.getProperties().put("gitShortCommitId", commitId); if (imageName != null) { imageName = expand(imageName); } if (baseImage != null) { baseImage = expand(baseImage); } } loadProfile(); validateParameters(); final String[] repoTag = parseImageName(imageName); final String repo = repoTag[0]; final String tag = repoTag[1]; if (useGitCommitId) { if (tag != null) { getLog().warn("Ignoring useGitCommitId flag because tag is explicitly set in image name "); } else if (commitId == null) { throw new MojoExecutionException("Cannot tag with git commit ID because directory not a git repo"); } else { imageName = repo + ":" + commitId; } } mavenProject.getProperties().put("imageName", imageName); final String destination = getDestination(); if (dockerDirectory == null) { final List<String> copiedPaths = copyResources(destination); createDockerFile(destination, copiedPaths); } else { final Resource resource = new Resource(); resource.setDirectory(dockerDirectory); resources.add(resource); copyResources(destination); } buildImage(docker, destination, buildParams()); tagImage(docker, forceTags); final DockerBuildInformation buildInfo = new DockerBuildInformation(imageName, getLog()); if ("docker".equals(mavenProject.getPackaging())) { final File imageArtifact = createImageArtifact(mavenProject.getArtifact(), buildInfo); mavenProject.getArtifact().setFile(imageArtifact); } // Push specific tags specified in pom rather than all images if (pushImageTag) { pushImageTag(docker, imageName, imageTags, getLog()); } if (pushImage) { pushImage(docker, imageName, getLog(), buildInfo, getRetryPushCount(), getRetryPushTimeout()); } // Write image info file writeImageInfoFile(buildInfo, tagInfoFile); }
From source file:cop.maven.plugins.AbstractRestToRamlMojo.java
License:Apache License
protected void executeWithExceptionsHandled() throws Exception { evaluator = new PluginParameterExpressionEvaluator(session, mojoExecution); checkOutputDirectoryExists();//from ww w .j a v a 2s .co m checkFileName(); FileUtils.write(new File(out, Config.YAML), readConfiguration(), encoding); StandardJavaFileManager fileManager = COMPILER.getStandardFileManager(null, null, Charset.forName(encoding)); List<JavaFileObject> compilationUnits = StreamSupport .stream(fileManager.getJavaFileObjectsFromFiles(getSourceFiles()).spliterator(), true) .collect(Collectors.toList()); if (compilationUnits.isEmpty()) getLog().warn("no source file(s) detected! Processor task will be skipped"); else { JavaCompiler.CompilationTask task = COMPILER.getTask(null, fileManager, null, getCompilerOptions(), null, compilationUnits); if (!task.call()) throw new Exception("error during compilation"); } }
From source file:hudson.gridmaven.MojoInfo.java
License:Open Source License
public MojoInfo(ExecutionEvent event) { this(event.getMojoExecution(), null, new XmlPlexusConfiguration(event.getMojoExecution().getConfiguration()), new PluginParameterExpressionEvaluator(event.getSession(), event.getMojoExecution())); }
From source file:hudson.maven.MojoInfo.java
License:Open Source License
public MojoInfo(ExecutionEvent event, long startTime) { this(event.getMojoExecution(), null, new XmlPlexusConfiguration(event.getMojoExecution().getConfiguration()), new PluginParameterExpressionEvaluator(event.getSession(), event.getMojoExecution()), startTime); }
From source file:io.takari.maven.testing.Maven30xRuntime.java
License:Open Source License
@Override public Mojo lookupConfiguredMojo(MavenSession session, MojoExecution execution) throws Exception { MavenProject project = session.getCurrentProject(); MojoDescriptor mojoDescriptor = execution.getMojoDescriptor(); Mojo mojo = container.lookup(Mojo.class, mojoDescriptor.getRoleHint()); ExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator(session, execution); Xpp3Dom configuration = null;//from www .j a va 2 s . c om Plugin plugin = project.getPlugin(mojoDescriptor.getPluginDescriptor().getPluginLookupKey()); if (plugin != null) { configuration = (Xpp3Dom) plugin.getConfiguration(); } if (configuration == null) { configuration = new Xpp3Dom("configuration"); } configuration = Xpp3Dom.mergeXpp3Dom(configuration, execution.getConfiguration()); execution.setConfiguration(configuration); finalizeMojoConfiguration(execution); PlexusConfiguration pluginConfiguration = new XmlPlexusConfiguration(execution.getConfiguration()); String configuratorHint = "basic"; if (mojoDescriptor.getComponentConfigurator() != null) { configuratorHint = mojoDescriptor.getComponentConfigurator(); } ComponentConfigurator configurator = container.lookup(ComponentConfigurator.class, configuratorHint); configurator.configureComponent(mojo, pluginConfiguration, evaluator, container.getContainerRealm()); return mojo; }