Java Code Examples for org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator#evaluate()
The following examples show how to use
org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator#evaluate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IncludeProjectDependenciesComponentConfigurator.java From incubator-hivemall with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private static void addProjectDependenciesToClassRealm( final ExpressionEvaluator expressionEvaluator, final ClassRealm containerRealm) throws ComponentConfigurationException { final 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); } }
Example 2
Source File: IncludeProjectDependenciesComponentConfigurator.java From protostuff-compiler with Apache License 2.0 | 6 votes |
private void addProjectDependenciesToClassRealm(ExpressionEvaluator expressionEvaluator, ClassRealm realm) 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) { realm.addURL(url); } }
Example 3
Source File: IncludeProjectDependenciesComponentConfigurator.java From protostuff with Apache License 2.0 | 6 votes |
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); } }
Example 4
Source File: WebProjectWebRootProvider.java From netbeans with Apache License 2.0 | 5 votes |
@Override public List<String> build(Xpp3Dom configRoot, ExpressionEvaluator eval) { List<String> webRoots = new ArrayList<>(); if (configRoot != null) { Xpp3Dom webResources = configRoot.getChild("webResources"); // NOI18N if (webResources != null) { Xpp3Dom[] resources = webResources.getChildren("resource"); // NOI18N for (Xpp3Dom resource : resources) { if (resource != null) { Xpp3Dom directory = resource.getChild("directory"); // NOI18N if (directory != null) { try { String directoryValue = (String) eval.evaluate(directory.getValue()); if (directoryValue != null && !"".equals(directoryValue.trim())) { // NOI18N webRoots.add(directoryValue); } } catch (ExpressionEvaluationException ex) { Exceptions.printStackTrace(ex); } } } } } } return webRoots; }
Example 5
Source File: IncludeProjectDependenciesComponentConfigurator.java From swagger-maven-plugin with Apache License 2.0 | 5 votes |
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); } }
Example 6
Source File: Info.java From netbeans with Apache License 2.0 | 4 votes |
@Messages({ "# {0} - dir basename", "LBL_misconfigured_project={0} [unloadable]", "# {0} - path to project", "TXT_Maven_project_at=Maven project at {0}" }) private String getDisplayName(NbMavenProject nb) { MavenProject pr = nb.getMavenProject(); if (NbMavenProject.isErrorPlaceholder(pr)) { return LBL_misconfigured_project(project.getProjectDirectory().getNameExt()); } String custom = project.getLookup().lookup(AuxiliaryProperties.class).get(Constants.HINT_DISPLAY_NAME, true); if (custom == null) { custom = NbPreferences.forModule(Info.class).get(MavenSettings.PROP_PROJECTNODE_NAME_PATTERN, null); } if (custom != null) { //we evaluate because of global property and property in nb-configuration.xml file. The pom.xml originating value should be already resolved. ExpressionEvaluator evaluator = PluginPropertyUtils.createEvaluator(project); try { Object s = evaluator.evaluate(custom); if (s != null) { //just make sure the name gets resolved String ss = s.toString().replace("${project.name)", "" + pr.getGroupId() + ":" + pr.getArtifactId()); return ss; } } catch (ExpressionEvaluationException ex) { //now just continue to the default processing LOG.log(Level.INFO, "bad display name expression:" + custom, ex); } } String toReturn = pr.getName(); if (toReturn == null) { String grId = pr.getGroupId(); String artId = pr.getArtifactId(); if (grId != null && artId != null) { toReturn = grId + ":" + artId; //NOI18N } else { toReturn = TXT_Maven_project_at(FileUtil.getFileDisplayName(project.getProjectDirectory())); } } return toReturn; }
Example 7
Source File: EarImpl.java From netbeans with Apache License 2.0 | 4 votes |
private MavenModule[] checkConfiguration(MavenProject prj, Object conf) { List<MavenModule> toRet = new ArrayList<MavenModule>(); if (conf != null && conf instanceof Xpp3Dom) { ExpressionEvaluator eval = PluginPropertyUtils.createEvaluator(project); Xpp3Dom dom = (Xpp3Dom) conf; Xpp3Dom modules = dom.getChild("modules"); //NOI18N if (modules != null) { int index = 0; for (Xpp3Dom module : modules.getChildren()) { MavenModule mm = new MavenModule(); mm.type = module.getName(); if (module.getChildren() != null) { for (Xpp3Dom param : module.getChildren()) { String value = param.getValue(); if (value == null) { continue; } try { Object evaluated = eval.evaluate(value.trim()); value = evaluated != null ? ("" + evaluated) : value.trim(); //NOI18N } catch (ExpressionEvaluationException e) { //log silently } if ("groupId".equals(param.getName())) { //NOI18N mm.groupId = value; } else if ("artifactId".equals(param.getName())) { //NOI18N mm.artifactId = value; } else if ("classifier".equals(param.getName())) { //NOI18N mm.classifier = value; } else if ("uri".equals(param.getName())) { //NOI18N mm.uri = value; } else if ("bundleDir".equals(param.getName())) { //NOI18N mm.bundleDir = value; } else if ("bundleFileName".equals(param.getName())) { //NOI18N mm.bundleFileName = value; } else if ("excluded".equals(param.getName())) { //NOI18N mm.excluded = Boolean.valueOf(value); } } } mm.pomIndex = index; index++; toRet.add(mm); } } } return toRet.toArray(new MavenModule[0]); }
Example 8
Source File: PomHelper.java From versions-maven-plugin with Apache License 2.0 | 4 votes |
/** * Takes a list of {@link org.apache.maven.model.Plugin} instances and adds associations to properties used to * define versions of the plugin artifact or any of the plugin dependencies specified in the pom. * * @param helper Our helper. * @param expressionEvaluator Our expression evaluator. * @param result The map of {@link org.codehaus.mojo.versions.api.PropertyVersionsBuilder} keyed by property name. * @param plugins The list of {@link org.apache.maven.model.Plugin}. * @throws ExpressionEvaluationException if an expression cannot be evaluated. */ private static void addPluginAssociations( VersionsHelper helper, ExpressionEvaluator expressionEvaluator, Map<String, PropertyVersionsBuilder> result, List<Plugin> plugins ) throws ExpressionEvaluationException { if ( plugins == null ) { return; } for ( Plugin plugin : plugins ) { String version = plugin.getVersion(); if ( version != null && version.contains( "${" ) && version.indexOf( '}' ) != -1 ) { version = StringUtils.deleteWhitespace( version ); for ( PropertyVersionsBuilder property : result.values() ) { // any of these could be defined by a property final String propertyRef = "${" + property.getName() + "}"; if ( version.contains( propertyRef ) ) { String groupId = plugin.getGroupId(); if ( groupId == null || groupId.trim().length() == 0 ) { // group Id has a special default groupId = APACHE_MAVEN_PLUGINS_GROUPID; } else { groupId = (String) expressionEvaluator.evaluate( groupId ); } String artifactId = plugin.getArtifactId(); if ( artifactId == null || artifactId.trim().length() == 0 ) { // malformed pom continue; } else { artifactId = (String) expressionEvaluator.evaluate( artifactId ); } // might as well capture the current value VersionRange versionRange = VersionRange.createFromVersion( (String) expressionEvaluator.evaluate( plugin.getVersion() ) ); property.addAssociation( helper.createPluginArtifact( groupId, artifactId, versionRange ), true ); if ( !propertyRef.equals( version ) ) { addBounds( property, version, propertyRef, versionRange.toString() ); } } } } addDependencyAssocations( helper, expressionEvaluator, result, plugin.getDependencies(), true ); } }
Example 9
Source File: PomHelper.java From versions-maven-plugin with Apache License 2.0 | 4 votes |
private static void addReportPluginAssociations( VersionsHelper helper, ExpressionEvaluator expressionEvaluator, Map<String, PropertyVersionsBuilder> result, List<ReportPlugin> reportPlugins ) throws ExpressionEvaluationException { if ( reportPlugins == null ) { return; } for ( ReportPlugin plugin : reportPlugins ) { String version = plugin.getVersion(); if ( version != null && version.contains( "${" ) && version.indexOf( '}' ) != -1 ) { version = StringUtils.deleteWhitespace( version ); for ( PropertyVersionsBuilder property : result.values() ) { final String propertyRef = "${" + property.getName() + "}"; if ( version.contains( propertyRef ) ) { // any of these could be defined by a property String groupId = plugin.getGroupId(); if ( groupId == null || groupId.trim().length() == 0 ) { // group Id has a special default groupId = APACHE_MAVEN_PLUGINS_GROUPID; } else { groupId = (String) expressionEvaluator.evaluate( groupId ); } String artifactId = plugin.getArtifactId(); if ( artifactId == null || artifactId.trim().length() == 0 ) { // malformed pom continue; } else { artifactId = (String) expressionEvaluator.evaluate( artifactId ); } // might as well capture the current value VersionRange versionRange = VersionRange.createFromVersion( (String) expressionEvaluator.evaluate( plugin.getVersion() ) ); property.addAssociation( helper.createPluginArtifact( groupId, artifactId, versionRange ), true ); if ( !propertyRef.equals( version ) ) { addBounds( property, version, propertyRef, versionRange.toString() ); } } } } } }
Example 10
Source File: PomHelper.java From versions-maven-plugin with Apache License 2.0 | 4 votes |
private static void addDependencyAssocations( VersionsHelper helper, ExpressionEvaluator expressionEvaluator, Map<String, PropertyVersionsBuilder> result, List<Dependency> dependencies, boolean usePluginRepositories ) throws ExpressionEvaluationException { if ( dependencies == null ) { return; } for ( Dependency dependency : dependencies ) { String version = dependency.getVersion(); if ( version != null && version.contains( "${" ) && version.indexOf( '}' ) != -1 ) { version = StringUtils.deleteWhitespace( version ); for ( PropertyVersionsBuilder property : result.values() ) { final String propertyRef = "${" + property.getName() + "}"; if ( version.contains( propertyRef ) ) { // Any of these could be defined by a property String groupId = dependency.getGroupId(); if ( groupId == null || groupId.trim().length() == 0 ) { // malformed pom continue; } else { groupId = (String) expressionEvaluator.evaluate( groupId ); } String artifactId = dependency.getArtifactId(); if ( artifactId == null || artifactId.trim().length() == 0 ) { // malformed pom continue; } else { artifactId = (String) expressionEvaluator.evaluate( artifactId ); } // might as well capture the current value VersionRange versionRange = VersionRange.createFromVersion( (String) expressionEvaluator.evaluate( dependency.getVersion() ) ); property.addAssociation( helper.createDependencyArtifact( groupId, artifactId, versionRange, dependency.getType(), dependency.getClassifier(), dependency.getScope(), dependency.isOptional() ), usePluginRepositories ); if ( !propertyRef.equals( version ) ) { addBounds( property, version, propertyRef, versionRange.toString() ); } } } } } }