Permalink
Browse files

initial load

git-svn-id: file:///opt/svn/repositories/sonatype.org/plugins/trunk/maven-crypto-plugin@69 c2a14038-686d-4adc-8740-a14e5738cb64
  • Loading branch information...
1 parent 5053068 commit 92f6dbc8b7054175e87a9952ca50565b55d1d861 oleg committed Aug 19, 2008
Showing with 157 additions and 0 deletions.
  1. +63 −0 pom.xml
  2. +94 −0 src/main/java/org/sonatype/maven/plugins/crypto/SetPasswordMojo.java
View
63 pom.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.sonatype.maven.plugins</groupId>
+ <artifactId>maven-crypto-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
+ <name>Maven Module - crypto</name>
+ <version>1.0-SNAPSHOT</version>
+ <description>Cryptography helper</description>
+ <prerequisites />
+ <inceptionYear>2007</inceptionYear>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <developers>
+ <developer>
+ <name>Oleg Gusakov</name>
+ <email>spam.to.this@gmail.com</email>
+ <roles>
+ <role>developer</role>
+ </roles>
+ <timezone>-8</timezone>
+ </developer>
+ </developers>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>2.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.artifact</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <version>3.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-cipher</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.4</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
+
@@ -0,0 +1,94 @@
+package org.sonatype.maven.plugins.crypto;
+
+import org.apache.maven.artifact.manager.CredentialsChangeRequest;
+import org.apache.maven.artifact.manager.CredentialsDataSource;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.Settings;
+import org.apache.maven.wagon.authentication.AuthenticationInfo;
+import org.codehaus.plexus.components.cipher.PlexusCipher;
+import org.codehaus.plexus.components.interactivity.Prompter;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ *
+ * @author Oleg Gusakov
+ *
+ * @goal set-server-password
+ */
+
+public class SetPasswordMojo
+extends AbstractMojo
+{
+ //----------------------------------------------------------------
+ /**
+ * @parameter expression="${serverid}"
+ */
+ String serverid;
+ //----------------------------------------------------------------
+ /**
+ * @parameter expression="${username}"
+ */
+ String username;
+ //----------------------------------------------------------------
+ /**
+ * @parameter expression="${password}"
+ */
+ String password;
+ //----------------------------------------------------------------
+ /**
+ * @parameter expression="${oldpassword}"
+ */
+ String oldpassword;
+ //----------------------------------------------------------------
+
+ /**
+ * @parameter expression="${session}"
+ */
+ MavenSession _session;
+//
+// /**
+// * @parameter expression="${project}"
+// */
+// MavenProject _project;
+//
+// /**
+// * @component
+// */
+// Prompter _prompter;
+ //----------------------------------------------------------------
+ public void execute()
+ throws MojoExecutionException, MojoFailureException
+ {
+ try {
+
+ if( _session == null )
+ throw new Exception("session not injected");
+
+getLog().info("\n------------------------------->");
+
+ AuthenticationInfo auth = new AuthenticationInfo();
+ auth.setUserName(username);
+ auth.setPassword(password);
+getLog().info("Auth = "+auth);
+
+ CredentialsChangeRequest req = new CredentialsChangeRequest( serverid, auth, oldpassword);
+getLog().info("Req = "+req);
+ CredentialsDataSource cds = (CredentialsDataSource) _session.getContainer().lookup(CredentialsDataSource.class);
+getLog().info("Cds = "+cds);
+ cds.set(req);
+
+ getLog().info("Password for "+serverid+" succesfully "+(oldpassword==null?"set":"reset") );
+
+ } catch( Exception e ) {
+ getLog().error("Error setting password for "+serverid+": "+e.getMessage() );
+ throw new MojoExecutionException( e.getMessage() );
+ }
+ }
+
+ //----------------------------------------------------------------
+ //----------------------------------------------------------------
+}

0 comments on commit 92f6dbc

Please sign in to comment.