hi jim,

now, CCed maven users list.

> worked! I am using Suse 10.0 and bash 3.0-17.

It's good to hear that!
To wrap up this issue, could you tell me what version of bash does not work?
I want to share with other people, the information about this limitation of this script.

thanks,
Takashi Nishigaya

jim stafford wrote:
Takashi,

worked! I am using Suse 10.0 and bash 3.0-17.

I can understand the differences in bash versions. I was confused by the fact that you version on the Maven site had no reference to looking up -Dproperties (help:describe) and your newgroup post and blog showed the command completion.

It also makes sense to me know how you were able to derive the groupId and arrtifactId. They have to be in a well know n set.

Even if it is debug, I'm happy with things just making sense.

thanks again,

jim

Takashi Nishigaya wrote:

hi jim,

It seems string escaping problem with different bash version. This is not useful discussion for maven users list. So, we had better continue to discuss the issue directly.

Could you please try the debug version of m2 attached in this mail.
And see what is happening using the following command:

$ tail -f /tmp/log.m2

Please send me the log.m2 file. I will try to investigate it.

Additionally, could you tell me your os, os version and bash version.

Thank you,
Takashi Nishigaya

jim stafford wrote:

Takashi,

I got -D args working with the following brute force method. Since it works, I haven't gone back to simplify. I could probably get rid of the if/else by adding the -- escape to your original compgen. That alone made me wonder how you got -D to complete since it wasn't escaped going into compgen.

However, your reply still makes it sound like something is being automated to get the -D arguments from the plugin:goal. As you see in my code, I hard coded the values. Is that consistent with what you have done locally?

If I can get this working, maybe I'll start using "mvn help:describe" more on the command line rather than plugging in keywords into google. I can never remember those long list of -D arguments for many of the commands.

thanks,
jim

_m2_make_archetype_args()
{
 opts="$opts -DlocalRepository="
 opts="$opts -DpackageName="
...

_m2_complete()
{
 local cur goals opts cmd
...
 goal=${COMP_WORDS[1]}

...
 goal=`echo $goal | sed 's/\\\\//g'`
 case "${goal}" in
    archetype:create)
          _m2_make_archetype_args
          ;;
  esac


 cur=`echo $cur | sed 's/\\\\//g'`
 if [ `echo "${cur}" | egrep ^- | wc -l` -ge 1 ]; then
     COMPREPLY=($(compgen -W "${opts}" -- ${cur} | sed 's/\\\\//g') )
 else
     COMPREPLY=($(compgen -W "${goals}" ${cur} | sed 's/\\\\//g') )
 fi
}



Takashi Nishigaya wrote:

hi jim,

> I tried this and it worked; almost. I assume you have to manually edit > the script to add the commands you care about. There is no magical way > to inspect the plugins available to the current pom.xml and kick out a
> list of their targets; right?

yes, it is difficult to inspect more suitable goals/targets candidates from your development environment like the current pom.xml. The current script is not perfect and not maintenance-free. You need to edit m2 file to fit your settings.

> However, beyond the <plugin>:<target> functionality, how did you
> get -D arguments working for your blog entry?

Did you mean that the inspection of -D arguments didn't work?
The parameter list for the plugin specified in the command line is retrieved by invoking mvn help:describe internally and cached in ~/.bash/completion/m2/. Therefore, you must be online, when you specify the plugin which parameter list is not cached yet.

Or, you may need to hit more <TAB>. ;-) More precisely,

$ mvn archetype:create <TAB>-D<TAB><TAB>

This is the behavior of bash completion, not my script.

thanks,
Takashi Nishigaya

jim stafford wrote:

Takashi.

I tried this and it worked; almost. I assume you have to manually edit the script to add the commands you care about. There is no magical way to inspect the plugins available to the current pom.xml and kick out a list of their targets; right?

I'm fine with editing the script (do you have a more fully populated one?). However, beyond the <plugin>:<target> functionality, how did you get -D arguments working for your blog entry?

$ mvn archetype:create <TAB>-D<TAB>
-DarchetypeArtifactId=
-DarchetypeArtifactId=maven-archetype-archetype
-DarchetypeArtifactId=maven-archetype-j2ee-simple
...

thanks,
jim



Takashi Nishigaya wrote:

Hi ccadete,

try my bash completion script:

http://blogs.sun.com/nishigaya/entry/bash_completion_for_maven_2

it will complemet plugin parameters as well as well-known plugin
goals.
the above entry is written in japanse, sorry. But you can easily
find the link for the actual bash completion script.

Thanks,
Takashi Nishigaya

ccadete wrote:



Yes, it was that, now it is working :) thanks.

ccadete



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


------------------------------------------------------------------------

#!/bin/bash
#
# bash completion for maven2
#
# Copyright (C) Takashi Nishigaya <[EMAIL PROTECTED]>
#
# http://blogs.sun.com/roller/page/nishigaya
#
# Release: 20060825

_m2_make_goals()
{
 plugin=$1
 mojos=$2
 if [ -z "$mojos" ]; then
   goals="$goals $plugin"
 else
   for mojo in $mojos
   do
     goals="$goals $plugin:$mojo"
   done
 fi
 export goals
}

_m2_make_params()
{
 param=$1
 values=$2
 if [ -z "$values" ]; then
   params="$params -D$param="
 else
   for value in $values
   do
     params="$params -D$param=$value"
   done
 fi
 export params
}

_m2_make_params_from_goal()
{
 goal=( $(echo $1 | sed 's/:/ /') )
 mkdir -p ~/.bash/completion/m2
 metafile=~/.bash/completion/m2/${goal[0]}-${goal[1]}
 if [ ! -f "$metafile" ]; then
   # plugins from apache
   params=$(mvn help:describe -DgroupId=org.apache.maven.plugins \
-DartifactId=maven-${goal[0]}-plugin -Dmojo=${goal[1]} \
                     -Dfull=true \
            | grep ' Name: ' \
            | sed 's/.*Name: \([a-zA-Z][a-zA-Z]*\).*/-D\1=/')
   # plugins from codehaus
   if [ -z "$params" ]; then
     params=$(mvn help:describe -DgroupId=org.codehaus.mojo \
-DartifactId=${goal[0]}-maven-plugin -Dmojo=${goal[1]} \
                     -Dfull=true \
            | grep ' Name: ' \
            | sed 's/.*Name: \([a-zA-Z][a-zA-Z]*\).*/-D\1=/')
   fi
   if [ -n "$params" ]; then
     echo "$params" > $metafile
   fi
 else
   params=$(cat $metafile)
 fi

 # add more useful params
 case "$1" in
   archetype:create)
     params=$params _m2_make_params "archetypeArtifactId" \
                                    "maven-archetype-archetype
                                     maven-archetype-j2ee-simple
                                     maven-archetype-mojo
                                     maven-archetype-portlet
                                     maven-archetype-profiles
                                     maven-archetype-quickstart
                                     maven-archetype-simple
                                     maven-archetype-site
                                     maven-archetype-site-simple
                                     maven-archetype-webapp"
     ;;
   help:describe)
     params=$params _m2_make_params "groupId" \
                                    "org.apache.maven.plugins
                                     org.codehaus.mojo"
     params=$params _m2_make_params "full" "true"
     ;;
   install:install-file)
     params=$params _m2_make_params "packaging" \
"jar war ejb ear rar par pom maven-plugin"
     ;;
 esac
 export params
}

_m2_make_goal_list()
{
 # plugins from apache
 goals=$goals _m2_make_goals "ant" "ant"
 goals=$goals _m2_make_goals "antlr" "generate"
 goals=$goals _m2_make_goals "antrun" "run"
 goals=$goals _m2_make_goals "archetype" "create-from-project create"
goals=$goals _m2_make_goals "assembly" "assembly attached directory-inline
                              directory single unpack"
 goals=$goals _m2_make_goals "checkstyle" "checkstyle check"
 goals=$goals _m2_make_goals "clean" "clean"
 goals=$goals _m2_make_goals "clover" "aggregate check instrumentInternal
                              instrument log clover save-history"
 goals=$goals _m2_make_goals "compiler" "compile testCompile"
 goals=$goals _m2_make_goals "core-it" "catch fork fork-goal touch
                              setter-touch generate-envar-properties
                              generate-properties loadable light-touch
package reachable runnable throw tricky-params"
 goals=$goals _m2_make_goals "deploy" "deploy-file deploy"
 goals=$goals _m2_make_goals "ear" "ear generate-application-xml"
 goals=$goals _m2_make_goals "eclipse" "add-maven-repo clean eclipse"
 goals=$goals _m2_make_goals "ejb" "ejb"
goals=$goals _m2_make_goals "help" "active-profiles describe effective-pom
                              effective-settings"
 goals=$goals _m2_make_goals "idea" "clean module idea project workspace"
 goals=$goals _m2_make_goals "install" "install-file install"
 goals=$goals _m2_make_goals "jar" "jar test-jar"
 goals=$goals _m2_make_goals "javadoc" "jar javadoc"
 goals=$goals _m2_make_goals "jxr" "jxr test-jxr"
 goals=$goals _m2_make_goals "one" "install-maven-one-repository
deploy-maven-one-repository maven-one-plugin"
 goals=$goals _m2_make_goals "plugin" "report updateRegistry
                              addPluginArtifactMetadata xdoc descriptor"
 goals=$goals _m2_make_goals "pmd" "cpd cpd-check pmd check"
 goals=$goals _m2_make_goals "project-info-reports" "cim dependencies
dependency-convergence issue-tracking license mailing-list index summary scm project-team"
 goals=$goals _m2_make_goals "projecthelp" "active-profiles describe
                              effective-pom effective-settings"
 goals=$goals _m2_make_goals "rar" "rar"
 goals=$goals _m2_make_goals "release" "clean perform prepare"
 goals=$goals _m2_make_goals "resources" "resources testResources"
goals=$goals _m2_make_goals "scm" "bootstrap changelog checkin checkout diff
                              edit status tag unedit update validate"
 goals=$goals _m2_make_goals "site" "deploy attach-descriptor site run
                              stage-deploy stage"
 goals=$goals _m2_make_goals "source" "jar test-jar"
 goals=$goals _m2_make_goals "surefire" "test"
 goals=$goals _m2_make_goals "surefire-report" "report"
 goals=$goals _m2_make_goals "verifier" "verify"
 goals=$goals _m2_make_goals "war" "exploded inplace manifest war"
 # plugins from codehaus
 goals=$goals _m2_make_goals "castor" "generate"
 goals=$goals _m2_make_goals "exec" "java exec"
 goals=$goals _m2_make_goals "javacc" "javacc jjtree"
 goals=$goals _m2_make_goals "jdepend" "generate"
 goals=$goals _m2_make_goals "taglist" "taglist"
}

_m2_complete()
{
 local cur prev lastgoal opts goals params

 COMPREPLY=()
 cur=$(echo ${COMP_WORDS[COMP_CWORD]} | sed 's/\\//g')
 prev=$(echo {COMP_WORDS[COMP_CWORD-1]} | sed 's/\\//g')
 for word in [EMAIL PROTECTED]
 # set last goal.
 do
   if [[ "$word" != -* ]]; then
     lastgoal=$(echo $word | sed 's/\\//g')
   fi
 done
 goals=$goals _m2_make_goal_list

 echo "## ------------------------------------">>/tmp/log.m2
 echo "## [EMAIL PROTECTED]">>/tmp/log.m2

 # return list of parameters for the last goal.
 if [[ "$goals" == *\ $lastgoal\ * ]]; then
   echo "## params, cur=${cur}, lastgoal=${lastgoal}">>/tmp/log.m2
   params=$params _m2_make_params_from_goal "$lastgoal"

   echo "## params, params=${params}">>/tmp/log.m2
   if [ -n "$params" ]; then
     COMPREPLY=($(compgen -W "${params}" -- ${cur}))
     return 0
   fi
 fi

 # return list of options.
 if [[ "$cur" == -* ]]; then
   echo "## option, cur=${cur}, lastgoal=${lastgoal}">>/tmp/log.m2
   opts='--strict-checksums --lax-checksums --activate-profiles
         --fail-fast --fail-at-end --batch-mode --fail-never
         --update-plugins --non-recursive --no-plugin-registry
         --update-snapshots --check-plugin-update --no-plugin-updates
         --define --debug --file --help --offline --reactor --settings
         --version
         -C -c -P -ff -fae -B -fn -up -N -npr -U -cpu -npu -D -X -e -f -h
         -o -r -s -v'
   COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
   return 0
 fi

 # default
 echo "## default, cur=${cur}, lastgoal=${lastgoal}">>/tmp/log.m2
 goals="$goals clean compile test install package deploy site"
 COMPREPLY=($(compgen -W "${goals}" ${cur} | sed 's/\\//g') )
}

complete -F _m2_complete -o filenames mvn



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to