You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Michael Hüttermann <mi...@huettermann.net> on 2012/08/24 11:36:32 UTC

access password in settings.xml

Hello,

how can I (e.g. programmatically, in an own Maven plugin) access the
"server">"password" element of settings.xml, to re-use the value. Is there
any chance to do so?



Thanks!

Michael

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


Re: access password in settings.xml

Posted by Manfred Moser <ma...@mosabuam.com>.
On Mon, August 27, 2012 1:11 pm, Mirko Friedenhagen wrote:
> /** Imports */
> import java.util.List;
> import org.apache.maven.plugin.AbstractMojo;
> import org.apache.maven.plugin.MojoExecutionException;
> import org.apache.maven.plugin.MojoFailureException;
> import org.apache.maven.plugins.annotations.Component;
> import org.apache.maven.settings.Server;
> import org.apache.maven.settings.Settings;
> import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
> import org.apache.maven.settings.crypto.SettingsDecrypter;
> import org.apache.maven.settings.crypto.SettingsDecryptionRequest;
> import org.apache.maven.settings.crypto.SettingsDecryptionResult;
>
> Note that I use guava in other parts as well so I did exclude it in
> the maven-plugin-api.
>
> /* POM */
>     <dependencies>
>         <dependency>
>             <groupId>org.apache.maven</groupId>
>             <artifactId>maven-plugin-api</artifactId>
>             <version>3.0.4</version>
>             <exclusions>
>                 <exclusion><!-- provided by com.google.guava:guava
> directly -->
>                     <artifactId>sisu-guava</artifactId>
>                     <groupId>org.sonatype.sisu</groupId>
>                 </exclusion>
>             </exclusions>
>         </dependency>

I think that you might want to remove this exclusion since sisu does more
than just guava.

manfred

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


Re: access password in settings.xml

Posted by Mirko Friedenhagen <mf...@gmail.com>.
/** Imports */
import java.util.List;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
import org.apache.maven.settings.crypto.SettingsDecrypter;
import org.apache.maven.settings.crypto.SettingsDecryptionRequest;
import org.apache.maven.settings.crypto.SettingsDecryptionResult;

Note that I use guava in other parts as well so I did exclude it in
the maven-plugin-api.

/* POM */
    <dependencies>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-plugin-api</artifactId>
            <version>3.0.4</version>
            <exclusions>
                <exclusion><!-- provided by com.google.guava:guava directly -->
                    <artifactId>sisu-guava</artifactId>
                    <groupId>org.sonatype.sisu</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugin-tools</groupId>
            <artifactId>maven-plugin-annotations</artifactId>
            <version>3.1</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.maven</groupId>
                    <artifactId>maven-artifact</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-settings</artifactId>
            <version>3.0.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-settings-builder</artifactId>
            <version>3.0.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-compat</artifactId>
            <version>3.0.4</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>13.0-rc2</version>
        </dependency>
</dependencies>

Regards Mirko

On Mon, Aug 27, 2012 at 4:20 PM, Michael Hüttermann
<mi...@huettermann.net> wrote:
> Hi Mirko,
> thanks! What are the necessary imports and the POM dependencies for that?
> Thanks.
>
>
> Michael
>
>
>
>> Hello Michael,
>>
>> reading your Agile ALM book right now :-):
>>
>> Here is an example how to get all servers with password decrypted:
>>
>> public class MyMojo extends AbstractMojo {
>>
>>     /**
>>      * Maven settings.
>>      */
>>     @Component
>>     private Settings settings;
>>     /**
>>      * The decrypter for passwords.
>>      */
>>     @Component
>>     private SettingsDecrypter settingsDecrypter;
>>
>>     /**
>>      * Returns the list of servers with decrypted passwords.
>>      *
>>      * @return list of servers with decrypted passwords.
>>      */
>>     List<Server> getDecryptedServers() {
>>         final SettingsDecryptionRequest settingsDecryptionRequest =
>> new DefaultSettingsDecryptionRequest();
>>         settingsDecryptionRequest.setServers(settings.getServers());
>>         final SettingsDecryptionResult decrypt =
>> settingsDecrypter.decrypt(settingsDecryptionRequest);
>>         return decrypt.getServers();
>>     }
>> }
>>
>> Regards Mirko
>> --
>> http://illegalstateexception.blogspot.com/
>> https://github.com/mfriedenhagen/
>> https://bitbucket.org/mfriedenhagen/
>> https://twitter.com/mfriedenhagen
>>
>>
>> On Fri, Aug 24, 2012 at 11:36 AM, Michael Hüttermann
>> <mi...@huettermann.net> wrote:
>>> Hello,
>>>
>>> how can I (e.g. programmatically, in an own Maven plugin) access the
>>> "server">"password" element of settings.xml, to re-use the value. Is
>>> there
>>> any chance to do so?
>>>
>>>
>>>
>>> Thanks!
>>>
>>> Michael
>>>
>>> ---------------------------------------------------------------------
>>> 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: access password in settings.xml

Posted by Michael Hüttermann <mi...@huettermann.net>.
Hi Mirko,
thanks! What are the necessary imports and the POM dependencies for that?
Thanks.


Michael



> Hello Michael,
>
> reading your Agile ALM book right now :-):
>
> Here is an example how to get all servers with password decrypted:
>
> public class MyMojo extends AbstractMojo {
>
>     /**
>      * Maven settings.
>      */
>     @Component
>     private Settings settings;
>     /**
>      * The decrypter for passwords.
>      */
>     @Component
>     private SettingsDecrypter settingsDecrypter;
>
>     /**
>      * Returns the list of servers with decrypted passwords.
>      *
>      * @return list of servers with decrypted passwords.
>      */
>     List<Server> getDecryptedServers() {
>         final SettingsDecryptionRequest settingsDecryptionRequest =
> new DefaultSettingsDecryptionRequest();
>         settingsDecryptionRequest.setServers(settings.getServers());
>         final SettingsDecryptionResult decrypt =
> settingsDecrypter.decrypt(settingsDecryptionRequest);
>         return decrypt.getServers();
>     }
> }
>
> Regards Mirko
> --
> http://illegalstateexception.blogspot.com/
> https://github.com/mfriedenhagen/
> https://bitbucket.org/mfriedenhagen/
> https://twitter.com/mfriedenhagen
>
>
> On Fri, Aug 24, 2012 at 11:36 AM, Michael Hüttermann
> <mi...@huettermann.net> wrote:
>> Hello,
>>
>> how can I (e.g. programmatically, in an own Maven plugin) access the
>> "server">"password" element of settings.xml, to re-use the value. Is
>> there
>> any chance to do so?
>>
>>
>>
>> Thanks!
>>
>> Michael
>>
>> ---------------------------------------------------------------------
>> 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: access password in settings.xml

Posted by Mirko Friedenhagen <mf...@gmail.com>.
Hello Michael,

reading your Agile ALM book right now :-):

Here is an example how to get all servers with password decrypted:

public class MyMojo extends AbstractMojo {

    /**
     * Maven settings.
     */
    @Component
    private Settings settings;
    /**
     * The decrypter for passwords.
     */
    @Component
    private SettingsDecrypter settingsDecrypter;

    /**
     * Returns the list of servers with decrypted passwords.
     *
     * @return list of servers with decrypted passwords.
     */
    List<Server> getDecryptedServers() {
        final SettingsDecryptionRequest settingsDecryptionRequest =
new DefaultSettingsDecryptionRequest();
        settingsDecryptionRequest.setServers(settings.getServers());
        final SettingsDecryptionResult decrypt =
settingsDecrypter.decrypt(settingsDecryptionRequest);
        return decrypt.getServers();
    }
}

Regards Mirko
--
http://illegalstateexception.blogspot.com/
https://github.com/mfriedenhagen/
https://bitbucket.org/mfriedenhagen/
https://twitter.com/mfriedenhagen


On Fri, Aug 24, 2012 at 11:36 AM, Michael Hüttermann
<mi...@huettermann.net> wrote:
> Hello,
>
> how can I (e.g. programmatically, in an own Maven plugin) access the
> "server">"password" element of settings.xml, to re-use the value. Is there
> any chance to do so?
>
>
>
> Thanks!
>
> Michael
>
> ---------------------------------------------------------------------
> 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: access password in settings.xml

Posted by Martin Gainty <mg...@hotmail.com>.
Manfred and Michael

rom what ive read gmaven has a hidden dependency on GROOVY being fully operational before gmaven-plugin will run so you're going to need to setup env vars
GROOVY_HOME
if "%GROOVY_HOME%" == "" set GROOVY_HOME=%DIRNAME%.
PROGNAME
PROGNAME=`basename "$0"`
GROOVY_OPTS
set GROOVY_OPTS="-Xmx128m"
set GROOVY_OPTS=%GROOVY_OPTS% -Dprogram.name="%PROGNAME%"
set GROOVY_OPTS=%GROOVY_OPTS% -Dgroovy.home="%GROOVY_HOME%"
STARTER_MAIN_CLASS
set STARTER_MAIN_CLASS=org.codehaus.groovy.tools.GroovyStarter
STARTER_CONF
set STARTER_CONF=%GROOVY_HOME%\conf\groovy-starter.conf
TOOLS_JAR
if exist "%JAVA_HOME%\lib\tools.jar" set TOOLS_JAR=%JAVA_HOME%\lib\tools.jar
Here is my groovy-starter.conf you can use to get you going

    # load required libraries
    load !{groovy.home}/lib/*.jar

    # load user specific libraries
    load !{user.home}/.groovy/lib/*.jar

    # tools.jar for ant tasks
    load ${tools.jar}

STARTER_CLASSPATH
set STARTER_CLASSPATH=%GROOVY_HOME%\lib\@GROOVYJAR@

you will also want to take a look at .\gradle\assemble.gradle to determine 
if you will build for an OSGI container
how to construct MANIFEST.MF
location of jars
location of starter classes
 
gradle has its own build environment so you're going to want to transfer all of the assemble.gradle properties and attributes over to your pom

also since groovy has to compile .groovy files to java you're going to want to ensure your groovy-compiler groovyc is operational run this Q&D script
%GROOVY_HOME%\src\bin\startGroovy.bat -classpath -classpath %GROOVY_HOME%\target\classes;%CLASSPATH% %GROOVY_HOME%\org.codehaus.groovy.tools.FileSystemCompiler .\src\main\java\org\codehaus\groovy\util\StringUtil.groovy

and verify StringUtil.class is produced

Have Fun
Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.


> Date: Fri, 24 Aug 2012 22:15:19 -0700
> Subject: Re: access password in settings.xml
> From: manfred@mosabuam.com
> To: michael@huettermann.net
> CC: users@maven.apache.org
> 
> On Fri, August 24, 2012 2:36 am, Michael Hüttermann wrote:
> > Hello,
> >
> > how can I (e.g. programmatically, in an own Maven plugin) access the
> > "server">"password" element of settings.xml, to re-use the value. Is there
> > any chance to do so?
> 
> Btw. you can also access collections from settings or pom programmatically
> with the gmaven plugin e.g. like this
> 
> <plugin>
>   <groupId>org.codehaus.gmaven</groupId>
>   <artifactId>gmaven-plugin</artifactId>
>   <executions>
>     <execution>
>       <phase>verify</phase>
>       <goals>
>         <goal>execute</goal>
>       </goals>
>   <configuration>
>   <source>
>     println "I am in ${project.name} version ${project.version}
>     project.dependencies.each {
>       println "Group: $it.groupId; Artifact: $it.artifactId; Version:
> $it.version"
>     }
>   </source>
>   </configuration>
> </plugin>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
 		 	   		  

Re: access password in settings.xml

Posted by Manfred Moser <ma...@mosabuam.com>.
On Fri, August 24, 2012 2:36 am, Michael Hüttermann wrote:
> Hello,
>
> how can I (e.g. programmatically, in an own Maven plugin) access the
> "server">"password" element of settings.xml, to re-use the value. Is there
> any chance to do so?

Btw. you can also access collections from settings or pom programmatically
with the gmaven plugin e.g. like this

<plugin>
  <groupId>org.codehaus.gmaven</groupId>
  <artifactId>gmaven-plugin</artifactId>
  <executions>
    <execution>
      <phase>verify</phase>
      <goals>
        <goal>execute</goal>
      </goals>
  <configuration>
  <source>
    println "I am in ${project.name} version ${project.version}
    project.dependencies.each {
      println "Group: $it.groupId; Artifact: $it.artifactId; Version:
$it.version"
    }
  </source>
  </configuration>
</plugin>

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


Re: access password in settings.xml

Posted by Olivier Lamy <ol...@apache.org>.
Maybe with :

    /**
     * The Maven Wagon manager to use when obtaining server
authentication details.
     */
    @Component
    private WagonManager wagonManager;

AuthenticationInfo info = wagonManager.getAuthenticationInfo( server );

server is the serverId String.

or using
    /**
     * The current user system settings for use in Maven.
     */
    @Component
    private Settings settings;
to have access to settings

2012/8/24 Michael Hüttermann <mi...@huettermann.net>:
> Hello,
>
> how can I (e.g. programmatically, in an own Maven plugin) access the
> "server">"password" element of settings.xml, to re-use the value. Is there
> any chance to do so?
>
>
>
> Thanks!
>
> Michael
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>



-- 
Olivier Lamy
Talend: http://coders.talend.com
http://twitter.com/olamy | http://linkedin.com/in/olamy

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