Plexus Utils
  1. Plexus Utils
  2. PLXUTILS-37

Ability to pick items from a list in a property declaration.

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.5.7
    • Labels:
      None
    • Environment:
      plexus-utils 1.4.3-SNAPSHOT
    • Testcase included:
      yes
    • Patch Submitted:
      Yes
    • Number of attachments :
      1

      Description

      I needed the ability to get values from lists in the Maven POM, like so:

      project.developers.0.id (should give me project.getDevelopers().get(0).getId()).

      I couldn't find how to do it, and after looking in the 1.4.3 trunk source of Plexus Utils, found that it was impossible to do as it stands (correct me if I'm wrong).

      This patch has been created using the premise that Java variable names cannot be numbers. Thus, if the property token is an integer, treat it as an index and call get(), otherwise continue as normal.

      The JUnit test for the affected class has been patched too, and runs successfully.

        Activity

        Hide
        Chris Hubick added a comment -

        What would be really nice is the ability to have some way to use an XPath!

        <project>
        ...
        <properties>
        <scm.user.name>${'urn:xpath:/project/developers/developer[properties/user.name="$

        {user.name}

        "]/id'}</scm.user.name>
        </properties>
        </project>

        Or that may be crazy talk?

        Show
        Chris Hubick added a comment - What would be really nice is the ability to have some way to use an XPath! <project> ... <properties> <scm.user.name>${'urn:xpath:/project/developers/developer[properties/user.name="$ {user.name} "]/id'}</scm.user.name> </properties> </project> Or that may be crazy talk?
        Hide
        Daniel Harvey added a comment -

        I'd love to see this patch incorporated.

        Show
        Daniel Harvey added a comment - I'd love to see this patch incorporated.
        Hide
        Vincent Siveton added a comment -

        Fixed in r8008

        The patch wasn't apply because I prefer to use the common JSP approach as defined in this Struts article.
        Mainly, you could use:

        • project.dependencies[0] if dependencies is a java.util.List object or an array object
        • project.dependenciesAsMap(dep1) if dependenciesAsMap is a java.util.Map object
        Show
        Vincent Siveton added a comment - Fixed in r8008 The patch wasn't apply because I prefer to use the common JSP approach as defined in this Struts article . Mainly, you could use: project.dependencies [0] if dependencies is a java.util.List object or an array object project.dependenciesAsMap(dep1) if dependenciesAsMap is a java.util.Map object
        Hide
        Costin Caraivan added a comment -

        It doesn't work. I don't know what kind of object <dependencies> is, but it's not a List (or at least it doesn't act like one), and it's not a Map. Neither of those methods work.

        Try:
        mvn help:evaluate, then $

        {project.dependenciesAsMap()}

        and $

        {project.dependencies[0]}
        Show
        Costin Caraivan added a comment - It doesn't work. I don't know what kind of object <dependencies> is, but it's not a List (or at least it doesn't act like one), and it's not a Map. Neither of those methods work. Try: mvn help:evaluate, then $ {project.dependenciesAsMap()} and $ {project.dependencies[0]}
        Hide
        Jörg Hohwiller added a comment -

        This issue is closed as fixed but it does not work.
        Could you please reopen. Even setting to "wontfix" is better than leaving as fixed.
        I would like to get the license via $

        {project.lincenses.0.license.name}

        or $

        {project.lincenses[0].license.name}

        but there seems to be no way to do so via variables.

        Show
        Jörg Hohwiller added a comment - This issue is closed as fixed but it does not work. Could you please reopen. Even setting to "wontfix" is better than leaving as fixed. I would like to get the license via $ {project.lincenses.0.license.name} or $ {project.lincenses[0].license.name} but there seems to be no way to do so via variables.
        Hide
        Renato Passos Santos added a comment -

        I would also like to ask to have this issue re-opened.

        Funniest thing is, when I use "mvn help:evaluate" on the command-line and then input "$

        {project.activeProfiles[0].id}" I have the correct answer. But when I try to use that expression during the build process to set a property to a given value - for example:

        <jdbc.url>jdbc:hsqldb:file:${project.build.directory}/arquivosDesenv/${project.activeProfiles[0].id}

        /db/$

        {db.name}

        .db;shutdown=true</jdbc.url>

        ...the "$

        {project.activeProfiles[0].id}

        " expression is the only one that is never evaluated to anything - all the others work. Actually, all of the above expression evaluates correctly during "mvn help:evaluate", but doesn't work at all in the build process itself!

        Show
        Renato Passos Santos added a comment - I would also like to ask to have this issue re-opened. Funniest thing is, when I use "mvn help:evaluate" on the command-line and then input "$ {project.activeProfiles[0].id}" I have the correct answer. But when I try to use that expression during the build process to set a property to a given value - for example: <jdbc.url>jdbc:hsqldb: file:${project.build.directory}/arquivosDesenv/$ {project.activeProfiles[0].id} /db/$ {db.name} .db;shutdown=true</jdbc.url> ...the "$ {project.activeProfiles[0].id} " expression is the only one that is never evaluated to anything - all the others work. Actually, all of the above expression evaluates correctly during "mvn help:evaluate" , but doesn't work at all in the build process itself!

          People

          • Assignee:
            Vincent Siveton
            Reporter:
            Jamie Burrell
          • Votes:
            7 Vote for this issue
            Watchers:
            11 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: