org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator Java Examples
The following examples show how to use
org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator.
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: PluginPropertyUtils.java From netbeans with Apache License 2.0 | 6 votes |
static @NonNull ConfigurationBuilder<String> simpleProperty(final @NonNull String property) { return new ConfigurationBuilder<String>() { @Override public String build(Xpp3Dom configRoot, ExpressionEvaluator eval) { if (configRoot != null) { Xpp3Dom source = configRoot.getChild(property); if (source != null) { String value = source.getValue(); if (value == null) { return null; } return value.trim(); } } return null; } }; }
Example #2
Source File: PluginPropertyUtils.java From netbeans with Apache License 2.0 | 6 votes |
static @NonNull ConfigurationBuilder<String[]> listProperty(final @NonNull String multiProperty, final @NonNull String singleProperty) { return new ConfigurationBuilder<String[]>() { @Override public String[] build(Xpp3Dom conf, ExpressionEvaluator eval) { if (conf != null) { Xpp3Dom dom = (Xpp3Dom) conf; // MNG-4862 Xpp3Dom source = dom.getChild(multiProperty); if (source != null) { List<String> toRet = new ArrayList<String>(); Xpp3Dom[] childs = source.getChildren(singleProperty); for (Xpp3Dom ch : childs) { String chvalue = ch.getValue() == null ? "" : ch.getValue().trim(); //NOI18N toRet.add(chvalue); //NOI18N } return toRet.toArray(new String[toRet.size()]); } } return null; } }; }
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: PluginPropertyUtils.java From netbeans with Apache License 2.0 | 6 votes |
/** * Evaluator usable for interpolating variables in non resolved (interpolated) models. * Should not be necessary when dealing with the project's <code>MavenProject</code> instance accessed via<code>NbMavenProject.getMavenProject()</code> * @since 2.57 */ public static @NonNull ExpressionEvaluator createEvaluator(@NonNull Project project) { NbMavenProjectImpl prj = project instanceof NbMavenProjectImpl ? (NbMavenProjectImpl)project : project.getLookup().lookup(NbMavenProjectImpl.class); assert prj != null; MavenProject mvnprj = prj.getOriginalMavenProject(); //the idea here is to tie the lifecycle of the evaluator to the lifecycle of the MavenProject, both //get changed when settings.xml is changed or pom is change or when a profile gets updated.. ExpressionEvaluator eval = (ExpressionEvaluator) mvnprj.getContextValue(CONTEXT_EXPRESSION_EVALUATOR); if (eval == null) { Settings ss = EmbedderFactory.getProjectEmbedder().getSettings(); ss.setLocalRepository(EmbedderFactory.getProjectEmbedder().getLocalRepository().getBasedir()); eval = new NBPluginParameterExpressionEvaluator( mvnprj, ss, prj.createSystemPropsForPropertyExpressions(), prj.createUserPropsForPropertyExpressions()); mvnprj.setContextValue(CONTEXT_EXPRESSION_EVALUATOR, eval); } return eval; }
Example #5
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 #6
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 #7
Source File: DMNMojoComponentConfigurator.java From jdmn with Apache License 2.0 | 5 votes |
@Override public void configureComponent(final Object component, final PlexusConfiguration configuration, final ExpressionEvaluator evaluator, final ClassRealm realm, final ConfigurationListener listener) throws ComponentConfigurationException { // Register custom type conversion for optionally-configurable types, i.e. those which can be specified as a // simple string or as a components with a name and configuration converterLookup.registerConverter(new OptionallyConfigurableComponentConverter()); super.configureComponent(component, configuration, evaluator, realm, listener); }
Example #8
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 #9
Source File: IncludeProjectDependenciesComponentConfigurator.java From swagger-maven-plugin with Apache License 2.0 | 5 votes |
@Override public void configureComponent(Object component, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm, ConfigurationListener listener) throws ComponentConfigurationException { addProjectDependenciesToClassRealm(expressionEvaluator, containerRealm); ObjectWithFieldsConverter converter = new ObjectWithFieldsConverter(); converter.processConfiguration(converterLookup, component, containerRealm.getClassLoader(), configuration, expressionEvaluator, listener); }
Example #10
Source File: MojoConfigurator.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
@Override public void configureComponent(final Object mojoInstance, // final PlexusConfiguration pluginConfigurationFromMaven, // final ExpressionEvaluator evaluator, // final ClassRealm realm, // final ConfigurationListener listener) throws ComponentConfigurationException { super.configureComponent(mojoInstance, pluginConfigurationFromMaven, evaluator, realm, listener); }
Example #11
Source File: IncludeProjectDependenciesComponentConfigurator.java From protostuff with Apache License 2.0 | 5 votes |
public void configureComponent(Object component, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm, ConfigurationListener listener) throws ComponentConfigurationException { addProjectDependenciesToClassRealm(expressionEvaluator, containerRealm); converterLookup.registerConverter(new ClassRealmConverter(containerRealm)); ObjectWithFieldsConverter converter = new ObjectWithFieldsConverter(); converter.processConfiguration(converterLookup, component, containerRealm.getClassLoader(), configuration, expressionEvaluator, listener); }
Example #12
Source File: IncludeProjectDependenciesComponentConfigurator.java From protostuff-compiler with Apache License 2.0 | 5 votes |
@Override public void configureComponent(Object component, PlexusConfiguration configuration, ExpressionEvaluator evaluator, ClassRealm realm, ConfigurationListener listener) throws ComponentConfigurationException { addProjectDependenciesToClassRealm(evaluator, realm); converterLookup.registerConverter(new ClassRealmConverter(realm)); ObjectWithFieldsConverter converter = new ObjectWithFieldsConverter(); converter.processConfiguration(converterLookup, component, realm.getParentClassLoader(), configuration, evaluator, listener); }
Example #13
Source File: IncludeProjectDependenciesComponentConfigurator.java From incubator-hivemall with Apache License 2.0 | 5 votes |
public void configureComponent(final Object component, final PlexusConfiguration configuration, final ExpressionEvaluator expressionEvaluator, final ClassRealm containerRealm, final ConfigurationListener listener) throws ComponentConfigurationException { addProjectDependenciesToClassRealm(expressionEvaluator, containerRealm); converterLookup.registerConverter(new ClassRealmConverter(containerRealm)); ObjectWithFieldsConverter converter = new ObjectWithFieldsConverter(); converter.processConfiguration(converterLookup, component, containerRealm.getClassLoader(), configuration, expressionEvaluator, listener); }
Example #14
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 #15
Source File: MavenSourceLevelImpl.java From netbeans with Apache License 2.0 | 5 votes |
@Override public String build(Xpp3Dom configRoot, ExpressionEvaluator eval) { if (configRoot != null) { Xpp3Dom args = configRoot.getChild("compilerArguments"); if (args != null) { Xpp3Dom prof = args.getChild("profile"); if (prof != null) { return prof.getValue(); } } } return null; }
Example #16
Source File: PluginPropertyUtils.java From netbeans with Apache License 2.0 | 5 votes |
/** * Evaluator usable for interpolating variables in non resolved (interpolated) models. * Should not be necessary when dealing with the project's <code>MavenProject</code> instance accessed via<code>NbMavenProject.getMavenProject()</code> * Please NOTE that if you have access to <code>Project</code> instance, then * the variant with <code>Project</code> as parameter is preferable. Faster and less prone to deadlock. * @since 2.32 */ public static @NonNull ExpressionEvaluator createEvaluator(@NonNull MavenProject prj) { ExpressionEvaluator eval = (ExpressionEvaluator) prj.getContextValue(CONTEXT_EXPRESSION_EVALUATOR); if (eval != null) { return eval; } Map<? extends String,? extends String> sysprops = Collections.emptyMap(); Map<? extends String,? extends String> userprops = Collections.emptyMap(); File basedir = prj.getBasedir(); if (basedir != null) { FileObject bsd = FileUtil.toFileObject(basedir); if (bsd != null) { Project p = FileOwnerQuery.getOwner(bsd); if (p != null) { NbMavenProjectImpl project = p.getLookup().lookup(NbMavenProjectImpl.class); if (project != null) { sysprops = project.createSystemPropsForPropertyExpressions(); userprops = project.createUserPropsForPropertyExpressions(); } } } } //ugly Settings ss = EmbedderFactory.getProjectEmbedder().getSettings(); ss.setLocalRepository(EmbedderFactory.getProjectEmbedder().getLocalRepository().getBasedir()); eval = new NBPluginParameterExpressionEvaluator( prj, ss, sysprops, userprops); prj.setContextValue(CONTEXT_EXPRESSION_EVALUATOR, eval); return eval; }
Example #17
Source File: PluginPropertyUtils.java From netbeans with Apache License 2.0 | 5 votes |
static @NonNull ConfigurationBuilder<Properties> propertiesBuilder(final @NonNull String propertyParameter) { return new ConfigurationBuilder<Properties>() { @Override public Properties build(Xpp3Dom conf, ExpressionEvaluator eval) { if (conf != null) { Xpp3Dom source = conf.getChild(propertyParameter); if (source != null) { Properties toRet = new Properties(); Xpp3Dom[] childs = source.getChildren(); for (Xpp3Dom ch : childs) { String val = ch.getValue(); if (val == null) { //#168036 //we have the "property" named element now. if (ch.getChildCount() == 2) { Xpp3Dom nameDom = ch.getChild("name"); //NOI18N Xpp3Dom valueDom = ch.getChild("value"); //NOI18N if (nameDom != null && valueDom != null) { String name = nameDom.getValue(); String value = valueDom.getValue(); if (name != null && value != null) { toRet.put(name, value); //NOI18N } } } // #153063, #187648 toRet.put(ch.getName(), ""); continue; } toRet.put(ch.getName(), val.trim()); //NOI18N } return toRet; } } return null; } }; }
Example #18
Source File: OptionallyConfigurableComponentConverter.java From jdmn with Apache License 2.0 | 5 votes |
@Override public Object fromConfiguration(ConverterLookup lookup, PlexusConfiguration configuration, Class<?> type, Class<?> enclosingType, ClassLoader loader, ExpressionEvaluator evaluator, ConfigurationListener listener) throws ComponentConfigurationException { OptionallyConfigurableMojoComponent component; if (configuration == null) { throw new ComponentConfigurationException("Cannot instantiate component from null configuration"); } // Instantiate the type as defined in Mojo configuration try { component = (OptionallyConfigurableMojoComponent)type.newInstance(); } catch (InstantiationException | IllegalAccessException ex) { throw new ComponentConfigurationException(String.format( "Cannot instantiate configurable component type \"%s\" (%s)", type.getName(), ex.getMessage()), ex); } if (component == null) { throw new ComponentConfigurationException(String.format( "Failed to instantiate new configurable component type \"%s\"", type.getName())); } // Verify that we are deserializing the expected content type if (!configuration.getName().equals(component.getElementName())) { throw new ComponentConfigurationException(String.format( "Invalid component element \"%s\"; component definition accepts only \"%s\" elements", configuration.getName(), component.getElementName())); } // Deserialize from either simple or compound data depending on structure of the input configuration if (configuration.getChildCount() == 0) { return configureSimpleComponent(component, configuration); } else { return configureCompoundComponent(component, configuration); } }
Example #19
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 #20
Source File: ModelRunConfig.java From netbeans with Apache License 2.0 | 4 votes |
@Override public String build(Xpp3Dom configRoot, ExpressionEvaluator eval) { if (configRoot != null) { Xpp3Dom domArgs = configRoot.getChild("arguments"); // NOI18N if (domArgs != null) { Xpp3Dom[] children = domArgs.getChildren(); if(children == null || children.length == 0) { return null; } Iterator<Xpp3Dom> it = Arrays.asList(children).iterator(); StringBuilder sb = new StringBuilder(); try { while(it.hasNext()) { Xpp3Dom xpp3Dom = it.next(); String val = null; if ("argument".equals(xpp3Dom.getName())) { // NOI18N val = xpp3Dom.getValue(); if (val == null || val.trim().isEmpty()) { continue; } val = val.trim(); if(val.contains("${")) { // not evaluated prop? LOG.log(Level.FINE, "skipping not evaluated property: {0}", val); // NOI18N val = null; } if ("-cp".equals(val) || "-classpath".equals(val)) { // NOI18N val = null; // the -cp/-classpath parameter is already in exec.args // lets assume that the following accords to // -cp/-classpath %classpath mainClass // 1.) the classpath tag Xpp3Dom dom = it.next(); if (dom != null && "classpath".equals(dom.getName())) { // NOI18N Xpp3Dom[] deps = dom.getChildren("dependency"); // NOI18N if (deps == null || deps.length == 0) { // the classpath argument results to '-classpath %classpath' // and that is already part of exec.args -> set them in the right // position as given by pom val = CP_PLACEHOLDER; } else { for (Xpp3Dom dep : deps) { if(dep != null) { String d = dep.getValue(); if(d != null && !d.trim().isEmpty()) { // explicitely declared deps - skip the whole thing. // would need to be resolved and we do not want // to reimplement the whole exec plugin LOG.log(Level.FINE, "skipping whole args evaluation due to explicitely declared deps"); // NOI18N return null; } } } } } // 2.) the main class // doesn't necessaryli have to be after "-cp %classpath", so do not skip. // it.next(); } } if (val != null && !val.isEmpty()) { if (sb.length() > 0) { sb.append(" "); // NOI18N } sb.append(val); } } } catch (NoSuchElementException e) { // ignore and return what you got } return sb.length() > 0 ? sb.toString() : null; } } return null; }
Example #21
Source File: MavenCommandLineExecutor.java From netbeans with Apache License 2.0 | 4 votes |
private File guessBestMaven(RunConfig clonedConfig, InputOutput ioput) { MavenProject mp = clonedConfig.getMavenProject(); if (mp != null) { if (mp.getPrerequisites() != null) { Prerequisites pp = mp.getPrerequisites(); String ver = pp.getMaven(); if (ver != null) { return checkAvailability(ver, null, ioput); } } String value = PluginPropertyUtils.getPluginPropertyBuildable(clonedConfig.getMavenProject(), Constants.GROUP_APACHE_PLUGINS, "maven-enforcer-plugin", "enforce", new PluginPropertyUtils.ConfigurationBuilder<String>() { @Override public String build(Xpp3Dom configRoot, ExpressionEvaluator eval) { if(configRoot != null) { Xpp3Dom rules = configRoot.getChild("rules"); if (rules != null) { Xpp3Dom rmv = rules.getChild("requireMavenVersion"); if (rmv != null) { Xpp3Dom v = rmv.getChild("version"); if (v != null) { return v.getValue(); } } } } return null; } }); if (value != null) { if (value.contains("[") || value.contains("(")) { try { VersionRange vr = VersionRange.createFromVersionSpec(value); return checkAvailability(null, vr, ioput); } catch (InvalidVersionSpecificationException ex) { Exceptions.printStackTrace(ex); } } else { return checkAvailability(value, null, ioput); } } } return null; }
Example #22
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 #23
Source File: DefaultVersionsHelper.java From versions-maven-plugin with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ public ExpressionEvaluator getExpressionEvaluator( MavenProject project ) { return new VersionsExpressionEvaluator( mavenSession, pathTranslator, project ); }
Example #24
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 #25
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 #26
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() ); } } } } } }
Example #27
Source File: LicenseHeaderPanelProvider.java From netbeans with Apache License 2.0 | 4 votes |
public Impl(final ModelHandle2 handle, Project prj, AuxiliaryProperties props) { this.handle = handle; this.props = props; this.project = prj; operation = new ModelOperation<POMModel>() { @Override public void performOperation(POMModel model) { if (licenseContent == null) { return; } try { ExpressionEvaluator createEvaluator = PluginPropertyUtils.createEvaluator(project); Object evaluate = createEvaluator.evaluate(licensePath); if(evaluate != null) { String eval = evaluate.toString(); File file = FileUtilities.resolveFilePath(handle.getProject().getBasedir(), eval); FileObject fo; if (!file.exists()) { fo = FileUtil.createData(file); } else { fo = FileUtil.toFileObject(file); } if (fo.isData()) { OutputStream out = fo.getOutputStream(); try { FileUtil.copy(new ByteArrayInputStream(licenseContent.getBytes()), out); } finally { out.close(); } } } else { Logger.getLogger(LicenseHeaderPanelProvider.class.getName()).log(Level.WARNING, "Encountered problems evaluating license path: {0}", licensePath); } } catch (IOException ex) { Exceptions.printStackTrace(ex); } catch (ExpressionEvaluationException ex) { Exceptions.printStackTrace(ex); } } }; licensePath = getProjectLicenseLocation(); }
Example #28
Source File: VersionsHelper.java From versions-maven-plugin with Apache License 2.0 | 2 votes |
/** * Returns an {@link ExpressionEvaluator} for the specified project. * * @param project The project. * @return an {@link ExpressionEvaluator} for the specified project. * @since 1.0-beta-1 */ ExpressionEvaluator getExpressionEvaluator( MavenProject project );
Example #29
Source File: PluginPropertyUtils.java From netbeans with Apache License 2.0 | votes |
T build(Xpp3Dom configRoot, ExpressionEvaluator eval);