You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Ben Anderson <be...@gmail.com> on 2004/10/29 19:03:15 UTC

dynamic property access

Hi,
I want to dynamically set which property I access.  Is this possible? 
Obviously the below code won't work, but you get the idea.  I thought
maybe that the <j:expr> tag might help, but it doesn't seem to do
anything.

    <j:set var="color" value="red"/>
    <j:set var="colorKey" value="color"/>
    <ant:echo>
        ${${colorKey}}
    </ant:echo>

Any ideas?

Thanks,
Ben

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: project dependency : strange problem

Posted by Brett Porter <br...@gmail.com>.
I'm not sure we've ever considered '.' to be valid in an artifactID,
but it certainly is in the groupId. try that, and if it still doesn't
work, file it as a bug.

I'd suggest a groupId of "com.abc.def" and artifactId of "F", for
example, and introduce some other process of renaming it to
${pom.groupId}.${pom.artifactId}-${pom.currentVersion}.jar when
publishing to the eclipse plugins directory (you can use
maven.final.name to change the name as it hits the target directory)

Cheers,
Brett

On Fri, 29 Oct 2004 13:05:33 -0700, Sachin Bansal <sb...@adobe.com> wrote:
> 
> Maven Users,
> 
> If I use maven multiproject:install-snapshot (SNAPSHOT) for the version
> information (for projects to figure out the dependencies on other projects)
> it works as long as the name of the project does not have a '.' in it.
> 
> That is if my sub-project names are like
> 
> myProject
>   foo
>   bar
>   hello
>   world
> 
> Then maven figures out the inter-dependencies among the projects and builds
> snapshot jars.
> 
> But if my sub-project are like following
> 
> myProject
>   com.abc.def.A
>   com.abc.def.B
>   com.abc.def.C
>   com.abc.def.D
>   com.abc.def.E
>   com.abc.def.F
> 
> Maven fails to figure out the inter-dependencies among the projects and
> looks for the "com.abc.deg.c-SNAPSHOT.jar (if my project com.abc.def.A
> depends on com.abc.def.C)
> 
> Has anyone else encountered the same problem? What is the work around, if I
> cannot change the name of my project (owing to the fact that they are
> eclipse plugins)
> I look forward to your suggestions. Also, the mailing list users have been
> really helpful in suggesting and guiding me to get up to speed on Maven.
> 
> I am using the command> maven multiproject:install-snapshot
> 
> Thanks,
> 
> Sachin
> 
> svbansal@yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: dynamic property access

Posted by Brett Porter <br...@gmail.com>.
<j:set var="var" value="servername.${env}" />
<ant:filter token="servername" value="${var}" />

or

<ant:filter token="servername"
value="${context.getVariable('servername.' + env)}" />

I'm not 100% certain the latter works.

- Brett

On Fri, 29 Oct 2004 14:17:46 -0400, Eric Giguere
<er...@videotron.ca> wrote:
> Ah, I see
> 
> I'm not sure if this is feasible...
> One thing sure, you cannot put an expression in an expression (
> ${...${}}. It just does not work with jelly.
> I've done a couple of tests with dynamic property names without success.
> 
> Eric.
> 
> 
> 
> 
> Ben Anderson wrote:
> 
> >yes, that's a solution for the example I gave, but not what I'm looking for.
> >Let me give the real example:
> >
> >config.properties
> >-----------------
> >servername.qa=qaServer
> >servername.prod=prodServer
> >
> >maven.xml
> >---------
> ><u:properties var="props" file="config.properties"/>
> ><j:forEach var="prop" items="${props}">
> >  <ant:copy file="${basedir}/WEB-INF/web.xml"
> >            tofile="${build.dir}/WEB-INF/web.xml"
> >            overwrite="true">
> >    <ant:filterset>
> >      <ant:filter token="servername" value="${servername.${env}}"/>
> >
> >
> >actually, this is probably a bit much.  Is there a way to solve the original
> >example w/out modifying the <j:set> tags?
> >
> >Thanks,
> >Ben
> >
> >Quoting Eric Giguere <er...@videotron.ca>:
> >
> >
> >
> >>Hello Ben
> >>Yep, try this:
> >>
> >>    <j:set var="color" value="red"/>
> >>    <j:set var="colorKey" value="${color}"/>
> >>    <ant:echo>
> >>        ${colorKey}
> >>    </ant:echo>
> >>
> >>
> >>Hope it helps
> >>Eric.
> >>
> >>Ben Anderson wrote:
> >>
> >>
> >>
> >>>Hi,
> >>>I want to dynamically set which property I access.  Is this possible?
> >>>Obviously the below code won't work, but you get the idea.  I thought
> >>>maybe that the <j:expr> tag might help, but it doesn't seem to do
> >>>anything.
> >>>
> >>>   <j:set var="color" value="red"/>
> >>>   <j:set var="colorKey" value="color"/>
> >>>   <ant:echo>
> >>>       ${${colorKey}}
> >>>   </ant:echo>
> >>>
> >>>Any ideas?
> >>>
> >>>Thanks,
> >>>Ben
> >>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >>>For additional commands, e-mail: users-help@maven.apache.org
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >>For additional commands, e-mail: users-help@maven.apache.org
> >>
> >>
> >>
> >>
> >
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >For additional commands, e-mail: users-help@maven.apache.org
> >
> >
> >
> >
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


project dependency : strange problem

Posted by Sachin Bansal <sb...@adobe.com>.
Maven Users,

If I use maven multiproject:install-snapshot (SNAPSHOT) for the version
information (for projects to figure out the dependencies on other projects)
it works as long as the name of the project does not have a '.' in it.

That is if my sub-project names are like

myProject
  foo
  bar
  hello
  world

Then maven figures out the inter-dependencies among the projects and builds
snapshot jars. 

But if my sub-project are like following

myProject
  com.abc.def.A
  com.abc.def.B
  com.abc.def.C
  com.abc.def.D
  com.abc.def.E
  com.abc.def.F

Maven fails to figure out the inter-dependencies among the projects and
looks for the "com.abc.deg.c-SNAPSHOT.jar (if my project com.abc.def.A
depends on com.abc.def.C)

Has anyone else encountered the same problem? What is the work around, if I
cannot change the name of my project (owing to the fact that they are
eclipse plugins)
I look forward to your suggestions. Also, the mailing list users have been
really helpful in suggesting and guiding me to get up to speed on Maven.

I am using the command> maven multiproject:install-snapshot

Thanks,
 
Sachin
 
svbansal@yahoo.com


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: dynamic property access

Posted by Eric Giguere <er...@videotron.ca>.
Ah, I see

I'm not sure if this is feasible...
One thing sure, you cannot put an expression in an expression ( 
${...${}}. It just does not work with jelly.
I've done a couple of tests with dynamic property names without success.

Eric.


Ben Anderson wrote:

>yes, that's a solution for the example I gave, but not what I'm looking for. 
>Let me give the real example:
>
>config.properties
>-----------------
>servername.qa=qaServer
>servername.prod=prodServer
>
>maven.xml
>---------
><u:properties var="props" file="config.properties"/>
><j:forEach var="prop" items="${props}">
>  <ant:copy file="${basedir}/WEB-INF/web.xml"
>            tofile="${build.dir}/WEB-INF/web.xml"
>            overwrite="true">
>    <ant:filterset>
>      <ant:filter token="servername" value="${servername.${env}}"/>
>
>
>actually, this is probably a bit much.  Is there a way to solve the original
>example w/out modifying the <j:set> tags?
>
>Thanks,
>Ben
>
>Quoting Eric Giguere <er...@videotron.ca>:
>
>  
>
>>Hello Ben
>>Yep, try this:
>>
>>    <j:set var="color" value="red"/>
>>    <j:set var="colorKey" value="${color}"/>
>>    <ant:echo>
>>        ${colorKey}
>>    </ant:echo>
>>
>>
>>Hope it helps
>>Eric.
>>
>>Ben Anderson wrote:
>>
>>    
>>
>>>Hi,
>>>I want to dynamically set which property I access.  Is this possible?
>>>Obviously the below code won't work, but you get the idea.  I thought
>>>maybe that the <j:expr> tag might help, but it doesn't seem to do
>>>anything.
>>>
>>>   <j:set var="color" value="red"/>
>>>   <j:set var="colorKey" value="color"/>
>>>   <ant:echo>
>>>       ${${colorKey}}
>>>   </ant:echo>
>>>
>>>Any ideas?
>>>
>>>Thanks,
>>>Ben
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>>For additional commands, e-mail: users-help@maven.apache.org
>>>
>>>
>>>
>>>
>>>      
>>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>>    
>>
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>For additional commands, e-mail: users-help@maven.apache.org
>
>
>  
>


Re: dynamic property access

Posted by Ben Anderson <be...@benanderson.us>.
yes, that's a solution for the example I gave, but not what I'm looking for. 
Let me give the real example:

config.properties
-----------------
servername.qa=qaServer
servername.prod=prodServer

maven.xml
---------
<u:properties var="props" file="config.properties"/>
<j:forEach var="prop" items="${props}">
  <ant:copy file="${basedir}/WEB-INF/web.xml"
            tofile="${build.dir}/WEB-INF/web.xml"
            overwrite="true">
    <ant:filterset>
      <ant:filter token="servername" value="${servername.${env}}"/>


actually, this is probably a bit much.  Is there a way to solve the original
example w/out modifying the <j:set> tags?

Thanks,
Ben

Quoting Eric Giguere <er...@videotron.ca>:

> Hello Ben
> Yep, try this:
>
>     <j:set var="color" value="red"/>
>     <j:set var="colorKey" value="${color}"/>
>     <ant:echo>
>         ${colorKey}
>     </ant:echo>
>
>
> Hope it helps
> Eric.
>
> Ben Anderson wrote:
>
> >Hi,
> >I want to dynamically set which property I access.  Is this possible?
> >Obviously the below code won't work, but you get the idea.  I thought
> >maybe that the <j:expr> tag might help, but it doesn't seem to do
> >anything.
> >
> >    <j:set var="color" value="red"/>
> >    <j:set var="colorKey" value="color"/>
> >    <ant:echo>
> >        ${${colorKey}}
> >    </ant:echo>
> >
> >Any ideas?
> >
> >Thanks,
> >Ben
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >For additional commands, e-mail: users-help@maven.apache.org
> >
> >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: dynamic property access

Posted by Eric Giguere <er...@videotron.ca>.
Hello Ben
Yep, try this:

    <j:set var="color" value="red"/>
    <j:set var="colorKey" value="${color}"/>
    <ant:echo>
        ${colorKey}
    </ant:echo>


Hope it helps
Eric.

Ben Anderson wrote:

>Hi,
>I want to dynamically set which property I access.  Is this possible? 
>Obviously the below code won't work, but you get the idea.  I thought
>maybe that the <j:expr> tag might help, but it doesn't seem to do
>anything.
>
>    <j:set var="color" value="red"/>
>    <j:set var="colorKey" value="color"/>
>    <ant:echo>
>        ${${colorKey}}
>    </ant:echo>
>
>Any ideas?
>
>Thanks,
>Ben
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>For additional commands, e-mail: users-help@maven.apache.org
>
>
>  
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: dynamic property access

Posted by Ben Anderson <be...@benanderson.us>.
Thanks Alex - that works!  However, I've realized I don't really need to do
this.  If anyone cares, here's my resolution that lets me add tokens to
property files dynamically w/out requiring a change in my maven.xml.  Nothing
special here - I just think it's pretty neat.

  <goal name="prop">
    <j:set var="envDir">.${env}</j:set>
    <ant:copy toDir="${maven.build.dest}"
              overwrite="true">
      <ant:fileset dir="${maven.src.dir}"
                   includes="*.properties"/>
      <ant:filterset>
        <u:properties var="props"
                     
file="${basedir}/../../environment/environment.properties"/>
        <j:forEach var="prop" items="${props}">
          <j:choose>
            <j:when test="${prop.key.endsWith(envDir)}">
              <j:set var="propKey">
                ${prop.key.substring(0, prop.key.indexOf(envDir))}
              </j:set>
              <ant:filter token="${propKey}" value="${prop.value}"/>
            </j:when>
            <j:when test="${!(prop.key.endsWith('qa') or
prop.key.endsWith('prod'))}">
              <ant:filter token="${prop.key}" value="${prop.value}"/>
            </j:when>
          </j:choose>
        </j:forEach>
      </ant:filterset>
    </ant:copy>
  </goal>


environment.properties
----------------------
server.name.qa=myQABox
server.name.prod=myProdBox
server.port=80

Some properties file to be filtered
-----------------------------------
serverName=@server.name@
serverPort=@server.port

now I can run:
maven -Denv=qa|prod someGoal

-Ben


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: dynamic property access

Posted by Alex Karasulu <ao...@bellsouth.net>.
Alex Karasulu wrote:

> Ben Anderson wrote:
>
>> Hi,
>> I want to dynamically set which property I access.  Is this possible? 
>> Obviously the below code won't work, but you get the idea.  I thought
>> maybe that the <j:expr> tag might help, but it doesn't seem to do
>> anything.
>>
>>    <j:set var="color" value="red"/>
>>    <j:set var="colorKey" value="color"/>
>>    <ant:echo>
>>        ${${colorKey}}
>>    </ant:echo>
>> Any ideas?
>>
>>  
>>
> Maybe if I'm right hehe - try this and if it makes things work:
>
> <j:set var="colorKey" value="${context.getVariable(color)}"/>
>
> or rather this would return "red":
>
> <ant:echo>
>     ${context.getVariable(colorKey)}
> </ant:echo>
>
> You could chain these calls too in the JEXL expression too if you had 
> multiple levels of indirection.
>
> Well guess it does not fit exactly this example which you point out 
> further down in this thread.  However I'm thinking what you want to do 
> is dynamically assemble a key value by resolving anther key.  I do 
> this for properties that associate values of an object like so:

>
> a.b.c.name=someobj
> a.b.c.class=CLI
> a.b.c.package=org.apache.maven
> a.b.c.interfaces=.....

You know I totally messed this up here are the correct property keys i 
was refering to above:

a.b.c.name=someobj
a.b.c.class.somebody=CLI
a.b.c.package.somebody=org.apache.maven
a.b.c.interfaces.somebody=.....

>
> I assemble these keys and look up their respective values using this 
> technique.
>
> Cheers,
> Alex
>
>> Thanks,
>> Ben
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>>  
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: dynamic property access

Posted by Alex Karasulu <ao...@bellsouth.net>.
Ben Anderson wrote:

>Hi,
>I want to dynamically set which property I access.  Is this possible? 
>Obviously the below code won't work, but you get the idea.  I thought
>maybe that the <j:expr> tag might help, but it doesn't seem to do
>anything.
>
>    <j:set var="color" value="red"/>
>    <j:set var="colorKey" value="color"/>
>    <ant:echo>
>        ${${colorKey}}
>    </ant:echo>
>Any ideas?
>
>  
>
Maybe if I'm right hehe - try this and if it makes things work:

<j:set var="colorKey" value="${context.getVariable(color)}"/>

or rather this would return "red":

<ant:echo>
     ${context.getVariable(colorKey)}
</ant:echo>

You could chain these calls too in the JEXL expression too if you had 
multiple levels of indirection.

Well guess it does not fit exactly this example which you point out 
further down in this thread.  However I'm thinking what you want to do 
is dynamically assemble a key value by resolving anther key.  I do this 
for properties that associate values of an object like so:

a.b.c.name=someobj
a.b.c.class=CLI
a.b.c.package=org.apache.maven
a.b.c.interfaces=.....

I assemble these keys and look up their respective values using this 
technique.

Cheers,
Alex

>Thanks,
>Ben
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>For additional commands, e-mail: users-help@maven.apache.org
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org